Skip to content

Instantly share code, notes, and snippets.

@r4z0r5
Created July 16, 2017 23:57
Show Gist options
  • Save r4z0r5/82d004fc2886244536f7dd7b1aafa830 to your computer and use it in GitHub Desktop.
Save r4z0r5/82d004fc2886244536f7dd7b1aafa830 to your computer and use it in GitHub Desktop.
#Hexadecimal to Binary conversion without any imports
hexnumbers = list('0123456789abcdef')
binnumbers = ('0000','0001','0010','0011','0100','0101','0110','0111','1000','1001','1010','1011','1100','1101','1110','1111')
print('Hexadecimal numbers are: ', hexnumbers)
userinput = input('Enter any hexadecimal number: ')
i = 0
result = ''
while i != len(userinput):
if userinput[i] not in hexnumbers:
print('What the fuck? I actually asked for hex numbers only')
exit()
else:
result += str(binnumbers[(hexnumbers.index(userinput[i]))]) + ' '
i += 1
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment