7. First Set bit #
Created Tuesday 30 June 2020
- Find the first set bit and return it with the LSB’s
e.g 101010100 ⇒ 100
We don’t now where the first 1 is, do manips, and we don’t
n = 101010100
n-1;// 101010011 // useless
-n; // 010101101
n & -n
- n & n-1
Turn off first set bit
n = 101010100
n-1;// 101010011
n & (n-1);// nothing was affected on the left