Simple solution using bitset and no bit manipulation


  • 2
    H
    uint32_t reverseBits(uint32_t n) {
        bitset<32>b(n);
        int aux;
        for(int i=0; i<=15; i++){
            aux = b[i];
            b[i] = b[31-i];
            b[31-i] = aux;
        }
        int ans = (uint32_t)(b.to_ulong());
        return ans;
    }

Log in to reply
 

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