**Problem**

You’re given two integers, `n`

and `m`

. Find position of the rightmost bit in which they differ in their binary representations (it is guaranteed that such a bit exists), counting from right to left.

Return the value of `2`

(0-based).^{position_of_the_found_bit}

**Example**

- For
`n = 11`

and`m = 13`

, the output should be

`differentRightmostBit(n, m) = 2`

.`11`

,_{10}= 10**1**1_{2}`13`

, the rightmost bit in which they differ is the bit at position_{10}= 11**0**1_{2}`1`

(0-based) from the right in the binary representations.

So the answer is`2`

.^{1}= 2 - For
`n = 7`

and`m = 23`

, the output should be

`differentRightmostBit(n, m) = 16`

.`7`

,_{10}= 111_{2}`23`

, i.e._{10}= 10111_{2}`00111 10111`

So the answer is

`2`

.^{4}= 16

**Solution**

(n ^ m) & -(n ^ m)

**Explanation**

Let’s take `n = 11`

and `m = 13`

for example.

`11`

_{10} = 1011_{2}

`13`

_{10} = 1101_{2}

If we do XOR operation with n and m, we have 1 in every position that differs between the two.

`11`

_{10} XOR 13_{10 }= 1011_{2} ^ 1101_{2} = 0110_{2}

Since we have a bit representation of the positions that differ, we need to find the rightmost 1.

There is a trick to this. Given a number, x,

x & -x gives the rightmost 1

`x = 6 = 0110`

_{2}

`-x = -6 = 1010`

_{2}

`x & -x = 0110`

_{2 }& 1010_{2}_{ }= 0010_{2}

So, (n^m) & -(n^m) is our answer.