Java solution, easy to understand


  • 0
    M
    public int reverseBits(int n) {
        int result = 0;
        for(int i = 0;i < 32; i++){
            if((n & (0x01 << i)) == (0x01 << i)){
                result += (0x01 << (31 - i));
            }
        }
        
        return result;
    }

Log in to reply
 

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