Solution 1

```
public int rangeBitwiseAnd(int m, int n) {
int mask = ~0;
while ((mask & m) != (mask & n)) mask <<= 1;
return mask & m;
}
```

Solution 2

```
public int rangeBitwiseAnd(int m, int n) {
while (n > m) n &= n - 1;
return m & n;
}
```