Created
November 11, 2014 16:28
-
-
Save noahbass/45cd187377f17b29b9ab to your computer and use it in GitHub Desktop.
convert an integer to a binary
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
i = 10 | |
nums = [] | |
if i == 0: | |
nums.append(0) | |
else: | |
while i >= 1: | |
if (i//2) % 2 == 0: | |
nums.append(1) | |
else: | |
nums.append(0) | |
i = i//2 | |
nums = nums[::-1] | |
print nums |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment