Thanks for your awesome solution and explanation.

I just wanted to clarify one minor thing:

Here:

Actually means, get its least significant set bit, correct?

E.g.

if diff = 2; then diff &= -diff becomes 2 &= -2 equals 2, in its binary format, it's 10, so its least significant set bit is 1 which is the last second bit.

Thanks.