x&(x-1) Explained

What is x - 1 wrt x x - 1 is derived from x by flipping all bits to the right of (and including) the rightmost set bit (1) in x to 0s. Examples x = 4 (100 in binary), x - 1 = 3 (011 in binary). x = 6 (110 in binary), x - 1 = 5 (101 in binary). What is X & (x-1)? x & (x - 1) results in a value with all bits from x remaining the same except for the rightmost set bit (1), which becomes 0. ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy