Isolating the Low-Order Bit
Let W be a non-zero word, where the word length is n. Then W is of the form
x....x10....0
\__ __/\__ __/
V V
n-k-1 k
where 0<=k<n
and the x's are arbitrary bits.
Assuming two's complement arithmetic,
W-1 = x....x01....1
_ _
-W = x....x10....0
_ _ _
W = x....x01....1
By using AND, OR and exclusive OR with various pairs of these quantities, useful new forms are obtained.
For example,
W AND W-1 xx...x00....0
\__ __/\__ __/
V V
n-k-1 k
thus removing the low-order 1 bit;
also W AND -W = 0....010....0
__ __/__ __/
V V
n-k-1 k
thus isolating the low-order bit.
Below, we will focus solely on this last result; however, in a particular application it may be advantageous to use a variation.