题目描述:
方法一:内置函数
class Solution: # @param n, an integer # @return an integer def reverseBits(self, n): return int(bin(n)[2:].zfill(32)[::-1],2)
方法二:位运算
class Solution: # @param n, an integer # @return an integer def reverseBits(self, n): res = 0 count = 32 while count: res <<= 1 # 取出 n 的最低位数加到 res 中 res += n&1 n >>= 1 count -= 1 return int(bin(res), 2)
原文:https://www.cnblogs.com/oldby/p/11218513.html