Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def hex2dec(ahex:str):
- ahex = ahex[::-1].upper()
- result = 0
- for i in range(0, len(ahex)):
- buff = ahex[i]
- if not buff.isdigit():
- if not buff in ["A","B","C","D","E","F"]:
- return None
- buff = {"A":"10",
- "B":"11",
- "C":"12",
- "D":"13",
- "E":"14",
- "F":"15"}.get(buff,0)
- result += int(buff) * 16**i
- return result
- valh = "ada"
- print(valh, hex2dec(valh),hex2dec(valh) == int(valh, 16))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement