Skip to content

Instantly share code, notes, and snippets.

@AKST
Last active December 16, 2015 12:09
Show Gist options
  • Save AKST/5432352 to your computer and use it in GitHub Desktop.
Save AKST/5432352 to your computer and use it in GitHub Desktop.
Reverse Binary with stdin
def reverse_bin (num):
reversed = 0
while num != 0:
reversed = (reversed << 1) | (num & 1)
num >>= 1
return reversed
if __name__ == "__main__":
print(reverse_bin(int(input())))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment