uint32_t reverseBits(uint32_t n) {
uint32_t a = 0x80000000;
uint32_t b = 0x1;
while (a>b){
uint32_t atmp = n&a;
uint32_t btmp = n&b;
if (atmp != 0){
n = (n|b);
}
else{
n = (n&~b);
}
if (btmp != 0){
n = (n|a);
}
else{
n = (n&~a);
}
a = a >> 1;
b = b << 1;
}
return n;
}
LeetCode: Reverse Bits
最新推荐文章于 2015-04-01 00:07:02 发布