mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-30 04:36:08 -04:00
11 lines
208 B
Python
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
|