This is a problem excersice from codesignal platform.

problem

Presented with the integer

`n`

, find the 0-based position of the second rightmost zero bit in its binary representation (it is guaranteed that such a bit exists), counting from right to left.Return the value of

`2`

.^{position_of_the_found_bit}Example

For

`n = 37`

, the output should be

`secondRightmostZeroBit(n) = 8`

.

`37`

. The second rightmost zero bit is at position_{10}= 100101_{2}`3`

(0-based) from the right in the binary representation of`n`

.

Thus, the answer is`2`

.^{3}= 8

answer:

/* You have to get rid of the rightmost 0 To fill in the rightmost 0 with 1 using x | (x + 1) 10111100 (x) | 10111101 (x + 1) -------- 10111101 Isolate the new rightmost 0 To isolate it use ~x & (x + 1) // now x is the value after step 1 10111101 (x) -------- 01000010 (~x) & 10111110 (x + 1) -------- 00000010 in short return ~(n|(n+1)) & ((n|(n+1))+1) ; */