Skip to content

Instantly share code, notes, and snippets.

@SteadBytes
Created November 8, 2017 07:31
Show Gist options
  • Save SteadBytes/b9487a9814acf8829521aae52f1b8e6e to your computer and use it in GitHub Desktop.
Save SteadBytes/b9487a9814acf8829521aae52f1b8e6e to your computer and use it in GitHub Desktop.
algorithm for converting integer to binary string (python3)
def int_to_bin(x):
if x == 0: return "0"
s = ''
while x:
if x & 1 == 1:
s = "1" + s
else:
s = "0" + s
x //= 2
return s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment