Just to count the bits used between the range and mask these bits.

```
public int rangeBitwiseAnd(int m, int n) {
int cnt= 0;
int diff= n - m;
while(diff!=0){
diff= diff>>1;
cnt++;
}
int result= 0;
result= m & n;
int mask= -1;
for(int i=0; i<cnt; i++){
mask= mask<<1;
}
result= result & mask;
return result;
}
```