Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dec2hex(x): #256
- dictHex = {0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8", 9: "9", 10: "A", 11: "B", 12: "C", 13: "D", 14: "E", 15: "F"}
- exp = 0
- while x >= (16 ** exp): #256 >= 16^0 (1), 16^1 (16), 16^2 (256)
- exp += 1 #1, 2, 3
- exp -= 1 #2
- if x <= 15: return dictHex[x]
- else: return dictHex[x//16**exp] + dec2hex(x%(16**exp)) #256%16^2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement