美文网首页计算机
Leetcode - Reverse Bits

Leetcode - Reverse Bits

作者: Richardo92 | 来源:发表于2016-09-29 09:45 被阅读1次

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

    本文链接:https://www.haomeiwen.com/subject/dimkyttx.html