2023-07-29 20:18:30 -07:00

11 lines
208 B
Python

def reverse_bits(n: int) -> int:
result, base = 0, 31
while n:
result += (n & 1) << base
n >>= 1
base -= 1
return result