链接 class Solution { public: uint32_t reverseBits(uint32_t n) { uint32_t ret = 0; for (int i = 0; i < 32; i++) { if (n & (1 << i)) { flipBit(ret, 31-i); } } return ret; } void flipBit(uint32_t &n, int i) { n ^= (1 << i); } }; 思路 一个32位的数,一次遍历,遇到1,则在相对应的位置上把零置为1;遇到零跳过; 要点 位操作:|(或)、&(与)、^(异或)、<<(向左移位)