Skip to content

Instantly share code, notes, and snippets.

@kigold
Last active September 19, 2016 16:13
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 kigold/12a812b3c43089e8e3a111ccfdd2e7e9 to your computer and use it in GitHub Desktop.
Save kigold/12a812b3c43089e8e3a111ccfdd2e7e9 to your computer and use it in GitHub Desktop.
def binary_converter(n):
if type(n) == str or n > 255 or n < 0:
print 'Invalid input'
return 'Invalid input'
if n == 0:
return '0'
numb = int(n)
result = []
while numb != 0:
result.append(numb%2)
numb = numb/2
print result
temp = ""
for i in range(len(result)-1, -1, -1):
temp +=str(result[i])
print temp
return temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment