class Solution {
public:
uint32_t reverseBits(uint32_t n) {
int ret = 0;
for (int i = 0; i < 32; i++)
{
int mask = 1 << i;
int tmp = mask & n;
tmp = (tmp >> i) & 1;
tmp = tmp << (32 - i - 1);
ret = ret | tmp;
}
return ret;
}
};
public:
uint32_t reverseBits(uint32_t n) {
int ret = 0;
for (int i = 0; i < 32; i++)
{
int mask = 1 << i;
int tmp = mask & n;
tmp = (tmp >> i) & 1;
tmp = tmp << (32 - i - 1);
ret = ret | tmp;
}
return ret;
}
};
评论
发表评论