public class Solution {
// you need treat n as an unsigned value
public int reverseBits(int n) {
int[] array = new int[32];
Arrays.fill(array, 0);
int p = 0;
while(n!=0){
array[p++] = n&1;
n = n>>>1;
}
int res = 0;
for(int i=0;i<32;++i){
if(array[i]==1){
res = (res<<1) + 1 ;
}else{
res<<=1;
}
}
return res;
}
}
// you need treat n as an unsigned value
public int reverseBits(int n) {
int[] array = new int[32];
Arrays.fill(array, 0);
int p = 0;
while(n!=0){
array[p++] = n&1;
n = n>>>1;
}
int res = 0;
for(int i=0;i<32;++i){
if(array[i]==1){
res = (res<<1) + 1 ;
}else{
res<<=1;
}
}
return res;
}
}