Problem
What
x & (-x) returns the rightmost 1 in binary representation of x.
-x is the two’s complement of x. -x will be equal to one’s complement of x plus 1.
Therefore (-x) will have all the bits flipped that are on the left of the rightmost 1 in x. So x & (-x) will return rightmost 1.
| |