Straightforward java solution


  • 0
    Z
    public class Solution {
        // you need treat n as an unsigned value
        public int reverseBits(int n) {
            int res = 0;
            for(int i=0;i<32;i++) {
                res = res|((n>>i&1)<<(31-i));
            }
            return res;
        }
    }
    

Log in to reply
 

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