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;
        
    }
};
posted @ 2020-02-11 17:28  Shendu.CC  阅读(95)  评论(0编辑  收藏  举报