How to perform binary transformations?

87 Views Asked by At

One of the steps in Binary Index Tree algorithm is to find a node's parent which is done by un-setting the rightmost SET bit. For example: if a node has index 1010 than it's parent is 1000. To apply such transformation the following method is applied:

1) Find 2's complement of the index.
2) AND the result of 1 with index.
3) Subtract the result from 2 with index.

If the following method is applied to 1010 then we get 1000 as the answer. Now I want to understand how to create such formulas? In Algebra we solve such type of problems by solving linear equations. How do we do it with Binary numbers to achieve such answers?