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;
        
    }
};

猜你喜欢

转载自www.cnblogs.com/dacc123/p/12295889.html