leetcode颠倒二进制位

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

你可能感兴趣的:(leetcode,算法,数据结构)