My 8ms-eays-to-understand C++ code


  • 0
    H

    With loop and pure bit manipulation.

    uint32_t reverseBits(uint32_t n) {
        uint32_t m = 0;
        uint32_t b;
        int i = 0;
        while(i < 32){
            b = n & 1; // get the last bit of current n
            n = n >> 1;
            m = (m << 1) | b;
            i ++;
        }
        
        return m;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.