Skip to content

Instantly share code, notes, and snippets.

@noahbass
Created November 11, 2014 16:28
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 noahbass/45cd187377f17b29b9ab to your computer and use it in GitHub Desktop.
Save noahbass/45cd187377f17b29b9ab to your computer and use it in GitHub Desktop.
convert an integer to a binary
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