Last active
September 19, 2016 16:13
-
-
Save kigold/12a812b3c43089e8e3a111ccfdd2e7e9 to your computer and use it in GitHub Desktop.
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 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