Just trying to reduce down to minimal code (character count), wondering if anyone can do much better
int rangeBitwiseAnd(int m, int n) {
int i=-1;
while(n-m>>++i);
return n&m>>i<<i;
}
Find the largest bit which isn't equal in both n and m (done here by looking at n-m, counted using 'i' variable). This bit, and all later ones, must be zero.
Take only bits which are 1 in both n and m, and not in the last i bits (done by right shifting then left shifting). This is the answer