【leetcode 位运算 C++】190. Reverse Bits

190. Reverse Bits

在这里插入图片描述

class Solution {
    
    
public:
    uint32_t reverseBits(uint32_t n) {
    
    
        uint32_t temp = 1, bit = 1, ans = 0;
        bit <<= 31;
        while(bit) {
    
    
            if(n & bit) ans += temp;
            temp <<= 1;
            bit >>= 1;
        }
        return ans;
    }
};

猜你喜欢

转载自blog.csdn.net/m0_37454852/article/details/113935933
今日推荐