Reverse Bits

原创 2015年07月09日 10:46:07
public class Solution {
    // you need treat n as an unsigned value
    public int reverseBits(int n) {
        for(int i = 0; i < 16; i++) {
            n = reversePair(n, i, 32 - i - 1);
        }
        return n;
    }
    private int reversePair(int n, int right, int left) {
        int a = (n >> right) & 1;
        int b = (n >> left) & 1;
        if ((a ^ b) != 0) {
            return n = n ^ (1 << right | 1 << left);
        }
        return n;
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

190. Reverse Bits\331. Verify Preorder Serialization of a Binary Tree

Reverse Bits description implementation Verify Preorder Serialization of a Binary Tree description i...

190. Reverse Bits [easy] (Python)

题目链接https://leetcode.com/problems/reverse-bits/题目原文 Reverse bits of a given 32 bits unsigned integ...

Leetcode - Reverse Bits

Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in b...

【LeetCode】Reverse Bits 翻转二进制

题目Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input ...

[LeetCode]Reverse Bits

QuestionReverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represen...

字节的按位逆序 Reverse Bits

http://www.hookcn.org/2011/01/reverse-bits.html   源自某公司的一道试题,问题很简单: 输入一个字节(8 bits),将其按位反序。 也就是说如...

Reverse Bits

Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented ...

[LeetCode][190][Reverse Bits]

题目链接:

Reverse Bits 及format()总结

题目详情:https://leetcode.com/problems/reverse-bits/description/自己写的代码:class Solution: # @param n, a...

【LeetCode-190】 Reverse Bits(C++)

题目要求:要求将一个32位无符号整数所对应的二进制位反转得到的无符号整数。 解题思路:一般这种对应于二进制位的题目要考虑位运算!!而我可能对于位运算不太熟悉,每次都是用最愚蠢的办法做,虽然AC了,但是...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)