**Problem**

You’re given two integers, `n`

and `m`

. Find position of the rightmost pair of equal bits in their binary representations (it is guaranteed that such a pair exists), counting from right to left.

Return the value of `2`

(0-based).^{position_of_the_found_pair}

**Example**

For `n = 10`

and `m = 11`

, the output should be

`equalPairOfBits(n, m) = 2`

.

`10`

, _{10} = 10**1**0_{2}`11`

, the position of the rightmost pair of equal bits is the bit at position _{10} = 10**1**1_{2}`1`

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

So the answer is `2`

.^{1} = 2

**Solution**

- ~(n ^ m) & ((n ^ m) + 1)
- ~(n ^ m) & -(~(n ^ m))

**Explanation**

Similar to previous post of “Different Rightmost Bit”, if we do XOR operation between the two numbers, we have 1 in every position that differs.

`n = 10`

_{10} = 1010_{2
}`m = 11`

_{10} = 1011_{2}

`n XOR m = 1010`

_{2 }^ 1011_{2 }= 0001_{2}

Since 1 bit means the two number differed in that position, the rightmost 0 bit is the rightmost position of equal bits.

Let’s take a complement of this.

`~0001`

_{2} = 1110_{2}

Now, the rightmost 1 bit is the rightmost position of equal bits.

There are two options to take now.

With our x = n ^ m,

- ~x & (x+1): AND operation with its complement and x+1
- ~x & -(~x): AND operation with its complement and negative complement
- Example is shown in the previous “Different Rightmost Bit” post