The basic idea is to check 32 times, the rightmost bit in n, if it's `equal to 1`

, add that bit to `res`

.

```
public int reverseBits(int n) {
int res = 0;
for (int i = 0; i < 32; i++) {
if ((n & 1) == 1)
res |= (1 << (31 - i));
n >>>= 1;
}
return res;
}
```