LeetCode 190 Reverse Bits
概述
https://leetcode.com/problems/reverse-bits/
直接法
class Solution {
public:
uint32_t reverseBits(uint32_t n) {
uint32_t a = 0;
for (int i = 0; i < 32; i ++) {
auto t = n >> i;
if (t % 2 == 1) {
int num = 31 - i;
auto mask = 1 << num;
a = a | mask;
}
}
return a;
}
};
Links: leetcode-190-reverse-bits