mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
15 lines
272 B
Python
15 lines
272 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# author: bt3gl
|
|
|
|
def reverse_bits(n: int) -> int:
|
|
|
|
result, base = 0, 31
|
|
|
|
while n:
|
|
result += (n & 1) << base
|
|
n >>= 1
|
|
base -= 1
|
|
|
|
return result
|