Skip to content

Instantly share code, notes, and snippets.

@ls0f ls0f/
Last active Jan 28, 2016

What would you like to do?
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
You can’t perform that action at this time.