Question: Given an integer, write an algorithm to convert it to 16 decimal, for negative numbers, you can use two's complement method
DEF tohex (NUM): "" " Decimal to Hexadecimal " "" DI = {10: ' A ' ,. 11: ' B ' , 12 is: ' C ' , 13 is: ' D ' , 14: ' E ' , 15: ' F ' } hexStr = "" IF NUM <0: # input negative NUM = NUM + 2 ** 32 the while NUM> = 16 : REST = 16% NUM # take the remainder hexStr = di.get(rest, str(rest)) + hexStr num //= 16 hexStr = di.get(num, str(num)) + hexStr return hexStr