Some preliminary remarks:
- The statement is true for when n is non-zero. There must be at least one 1-bit.
- A bitwise AND-operation copies the bits that are the same in both operands (
1&1==1
and 0&0==0
), and produces a zero bit when the corresponding bits are different (1&0==0
and 0&1==0
).
Subtraction of 1 is easy when n is odd: you just clear that final 1-bit and you're done. When n is not odd, you need to "borrow" from an adjacent bit, which leads to a potential cascade of borrowing, until you find a 1-bit you can borrow from (See American method for manual subtraction on Wikipedia). This means that starting from the right (at the least significant bit of n), you flip bits one by one, until the first 1-bit is encountered, which is also flipped.
So in a subtraction you flip a group of bits which includes exactly one 1-bit, which by consequence is the only one that gets flipped to a 0-bit.
As the bit-wise AND-operation on n will produce a 0 for every bit that was flipped for getting n-1, but will keep any other bit of n as it was before, it actually clears one 1-bit of n.
From this follows also that the bit that is cleared, is always the least significant 1-bit in n.