Good night, I'm trying to do two functions one to convert hexadecimal numbers to decimals and one to convert octal numbers to decimals, this is my code:
def hexadecimalparadecimal(n):
decimal = 0
n = str(n)
n = n[::-1]
tam = len(n)
num = list("0123456789ABCDEF")
for i in range(tam):
if n[i] == '1':
decimal = decimal + 16**i
print('EM DECIMAL: {}'.format (decimal))
return decimal
The problem that the conversion is wrong, when I compare the string with a 1 is fine, but I still could not use all the values, I tried the values in a list and compare but it gave error, in addition I tried to make A = 10, B = 11 even more I could not enter the letter receiving its values, in octal I do not have this problem with letters but I have not been able to do the sum of all values, use the numbers in the list, someone knows how to use the list in this case?