Lowest Set Bit
Return the value of the lowest 1 bit in the binary form of the non-negative integer n. For n = 12, binary 1100, the lowest 1 bit is the one worth 4, so return 4. For n = 0 there is no 1 bit, so return 0. The answer is always 0 or a power of two.
Example 1
n 12
returns 4
12 is 1100 in binary; its lowest 1 bit sits in the position worth 4.
Example 2
n 7
returns 1
7 is 111, whose lowest bit is already 1, worth 1.
Constraints
0 <= n < 2**31
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Bits problems
- Parity BitBeginner
- Read One BitBeginner
- Read a Binary StringBeginner
- Set Bit PositionsBeginner
- Switch Off the Lowest OneBeginner
- Add Without PlusEasy
- Alternating BitsEasy
- Binary GapEasy