classSolution:defreverseBits(self, n:int)->int:
ans =0
i =32# 循环移动32次while i >0:# 向左移动
ans <<=1# 移动后将末尾加n的尾部值
ans += n&1# 跟新n值,以取到最后的值
n >>=1
i -=1return ans
题目1题解1class Solution: def reverseBits(self, n: int) -> int: ans = 0 i = 32 # 循环移动32次 while i > 0: # 向左移动 ans <<= 1 # 移动后将末尾加n的尾部值 ans += n&1