60 likes | 121 Views
Learn how to effectively define and manipulate large integers with short formulas to work with long bitstrings. Explore useful formulas for performing complex bitstring manipulations.
E N D
Bitstring Manipulation • Once we know how to define and manipulate large integers with short formulas, we are on our way to manipulating long bitstrings. Here are some useful formulas that will help us with this task.
Here is an explanation of the formula bitn(x, y). Suppose x and y are numbers satisfying bitn(x, y). Because y is a power of two, its binary representation consists of a 1 followed by a string of zeros. The formula bitn(x, y) is true precisely when x’s bit in the same position as the 1 in y is 1. We get hold of this bit in x by dividing x by y using integer division; the quotient q and remainder r are the binary numbers illustrated. The bit we are interested in is 1 iffq is odd.
This formula is useful for treating numbers as bit strings of exponential length and indexing into them with other numbers to extract bits.