Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. def dec2hex(x): #256
  2. 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"}
  3. exp = 0
  4. while x >= (16 ** exp): #256 >= 16^0 (1), 16^1 (16), 16^2 (256)
  5. exp += 1 #1, 2, 3
  6. exp -= 1 #2
  7. if x <= 15: return dictHex[x]
  8. else: return dictHex[x//16**exp] + dec2hex(x%(16**exp)) #256%16^2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement