Created
February 18, 2019 22:32
-
-
Save otykhonruk/3560b7be4dc9caff0512c83bb3a6c29e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverse_bits(n): | |
assert 1 <= n <= 1000000000,\ | |
'argument must be in range [1, 1000000000]' | |
r = 0 | |
while n: | |
r <<= 1 | |
r |= n & 1 | |
n >>= 1 | |
return r | |
if __name__ == '__main__': | |
import sys | |
if len(sys.argv) > 1 and sys.argv[1].isdigit(): | |
print(reverse_bits(int(sys.argv[1]))) | |
else: | |
print('Usage: {} <N>'.format(sys.argv[0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment