For any number i, i & (i - 1) will flip the least bit of ‘1’. when i becomes zero, the count of 1 could be seen. (Q-191)
The result of a & (-a) (equivalent to a & (∼(a−1))) is to keep only the last 1 of the binary representation of a, and set the remaining 1s to 0.
a | (∼a) = −1
For ruby complement number: num = “1xxxxZZZZ”, (x, z ={0, 1}). we could use 2**31 - num to get the real value
Negative numbers representation: 2**32 + num when num < 0
get number from unsigned_part and “-”: unsigned_part - 2**31
x & (-x) is a way to isolate the rightmost 1-bit, moving last significant bit to 0. This operation is essential operation for Binary Indexed Tree(or Fenwick Tree).