题目链接：190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.
n = 00000010100101000001111010011100
Explanation: The input binary string
00000010100101000001111010011100represents the unsigned integer
43261596, so return
964176192which its binary representation is
n = 11111111111111111111111111111101
Explanation:The input binary string
11111111111111111111111111111101represents the unsigned integer
4294967293, so return
3221225471which its binary representation is
If this function is called many times, how would you optimize it?
- Note that in some languages such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer’s internal binary representation is the same, whether it is signed or unsigned.
- In Java, the compiler represents the signed integers using
2's complement notation. Therefore, in Example 2 above, the input represents the signed integer
-3and the output represents the signed integer
- The input must be a binary string of length
GitHub 代码同步地址： 190.ReverseBits.cpp