Topic link: https: //leetcode-cn.com/problems/reverse-bits/
Subject description:
Reversed given 32-bit unsigned binary integer.
Example:
Example 1:
输入: 00000010100101000001111010011100
输出: 00111001011110000010100101000000
解释: 输入的二进制串 00000010100101000001111010011100 表示无符号整数 43261596,
因此返回 964176192,其二进制表示形式为 00111001011110000010100101000000。
Example 2:
输入:11111111111111111111111111111101
输出:10111111111111111111111111111111
解释:输入的二进制串 11111111111111111111111111111101 表示无符号整数 4294967293,
因此返回 3221225471 其二进制表示形式为 10101111110010110010011101101001。
Ideas:
A thought: library functions
class Solution:
# @param n, an integer
# @return an integer
def reverseBits(self, n):
return int("{:032b}".format(n)[::-1], 2)
Thinking two: bit computing