Skip to content

Instantly share code, notes, and snippets.

@ls0f
Last active January 28, 2016 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ls0f/b4cbf768ad279789e365 to your computer and use it in GitHub Desktop.
Save ls0f/b4cbf768ad279789e365 to your computer and use it in GitHub Desktop.
int2bin
def int2bin(num):
s = ''
while num > 0:
s = ('1' if num & 1 else '0') + s
num >>= 1
return s if s else '0'
if __name__ == "__main__":
assert int2bin(12345) == bin(12345)[2:]
assert int2bin(5) == bin(5)[2:]
assert int2bin(524) == bin(524)[2:]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment