Last active
January 28, 2016 02:49
-
-
Save ls0f/b4cbf768ad279789e365 to your computer and use it in GitHub Desktop.
int2bin
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 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