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

```
int differentRightmostBit(int n, int m) {
System.out.println(Integer.toBinaryString(n^m));
System.out.println(Integer.toBinaryString((~(n^m))));
return (~(n^m)+1)&(n^m);
}
```

this is a similar problem to the last bitwise problem I posted this week.

- Turning all the different bits to 1 is straightforward with xor:

n XOR m - Turning all the bits to 0 is also straightforward with AND and NOT:

(n XOR m) AND (NOT(x XOR m))

if you n & ~n you get 0 but if you n & ~n+1 you get the first value that was 1.