mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-22 16:31:15 -04:00
👾
This commit is contained in:
parent
1d44d182e2
commit
a85ed914d3
320 changed files with 0 additions and 0 deletions
14
bit_operations/reverse_bits.py
Normal file
14
bit_operations/reverse_bits.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
#!/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
|
Loading…
Add table
Add a link
Reference in a new issue