Leetcode - Reverse Bits

My code:

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

reference:
https://discuss.leetcode.com/topic/53210/easy-understand-java-solution-with-comments

Anyway, Good luck, Richardo! -- 09/28/2016

你可能感兴趣的:(Leetcode - Reverse Bits)