Why does (x-1) toggle all the bits from the rightmost set bit of x?
问题 Why does this property hold true? say the kth bit from right side is the first set bit in number 'x'. (x-1) will toggle every bit upto kth bit from right side. I can verify this property by writing the bit sequence for the numbers but I don't understand as to why this property is true? Can anyone help me with a simple proof or intuition as to why this works? 回答1: Let's do a hand subtraction xxx100...00 - xxx000...01 ───────────── xxx011...11 x represents bits that we don't care Starting from