題目1
題解1
class Solution:
def reverseBits(self, n: int) -> int:
ans = 0
i = 32
# 循環移動32次
while i > 0:
# 向左移動
ans <<= 1
# 移動後將末尾加n的尾部值
ans += n&1
# 跟新n值,以取到最後的值
n >>= 1
i -= 1
return ans