play with bits

This commit is contained in:
bt3gl 2023-07-29 20:18:30 -07:00 committed by GitHub
parent c77eb0dd00
commit 4b22537ee7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 0 deletions

View file

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