Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- default_timer = 2 #Change default time added for each hex value you want to convert
- print "Each hex character will add {} seconds on the timer...".format(default_timer)
- inputHex = raw_input('Input Hex Value: ')
- calc_time = default_timer * len(inputHex) #Calculate how much time for user to calculate binary
- bConvert = bin(int(inputHex, 16)) #Convert to hex
- bits = len(bConvert[2:]) #Get length to pad zeros if needed..
- bConvertNew = bConvert[2:].zfill(bits) #New variable because converting hex will also add 0b at the
- #Space out the binary every 4 bits (so we can see each hex in binary)
- spacedConvert = [bConvertNew[i:i+4] for i in range(0, len(bConvertNew), 4)] #Will convert to list
- spacedConvert = ' '.join([bConvertNew[i:i+4] for i in range(0, len(bConvertNew), 4)]) #Rejoin list with space in between the binary values...
- print "Start...You have {} seconds to convert\n\n".format(calc_time)
- time.sleep(calc_time)
- print spacedConvert
Advertisement
Add Comment
Please, Sign In to add comment