LeetCode 190. Reverse Bits (位运算)

题目

很简单的位运算题目

class Solution {
public:
    uint32_t reverseBits(uint32_t n) {
        
        uint32_t ans;
        
        int pos = 0;
        while(pos<=31)
        {
            ans <<= 1;
            ans |= (n&1);
            n >>=1;
            pos++;
        }
        
        return ans;
        
    }
};

你可能感兴趣的:(LeetCode 190. Reverse Bits (位运算))