190. 颠倒二进制位

1
2
3
4
5
6
7
8
9
10
11
12
public class Solution {
// you need treat n as an unsigned value
public int reverseBits(int n) {
int ans = 0;
for (int i = 0; i < 32; i++) {
ans = ans << 1;
ans = (n&1) | ans;
n = n >> 1;
}
return ans;
}
}