HEX = "0123456789ABCDEF" # takes decimal int and return a hex string, the string should have exactly # length d (number of hex digits), unless more are needed to represent n def dechex(n,d): hs = "" while n>0 or d>0: last4 = n%16 hs = HEX[last4] + hs n = n//16 d -= 1 #while return hs #dechex XEH = {} i = 0 while i<16: XEH[HEX[i]] = i i += 1 #while # hs is a hex string such as "F7B", and return decimal int def hexdec(hs): n = 0 i = 0 while i=0: digit = XEH[ hs[i] ] # 0-15 n += digit* (16**(len(hs)-1-i)) i -= 1 # return n """ return n #hexdec h = dechex(123,4) print(h) print(hexdec(h))