public class Solution { // you need treat n as an unsigned value public int reverseBits(int n) { int res=0; for(int i=0;i<32;i++) { int yuan=1; int temp=yuan<<i; if(i<=15) res=((temp&n)<<(31-2*i)|res); else res=((temp&n)>>>((i-15)*2-1)|res); } return res; } }