I'm trying to write a function that converts hexadecimal to decimal. I have two problems. I can't get it to replace all letters with a number. It replaces a letter and then stops. Second, how do I get it so that it consecutively adds each integer?
def toDecimal(hexidecimal):
decimal=[hexidecimal[i:i+1] for i in range(0,len(hexidecimal), 1)]
for i in range(0,len(decimal)):
if 'a' in decimal:
decimal[i]='10'
if 'b' in decimal:
decimal[i]='11'
if 'c' in decimal:
decimal[i]='12'
if 'd' in decimal:
decimal[i]='13'
if 'e' in decimal:
decimal[i]='14'
if 'f' in decimal:
decimal[i]='15'
return decimal
#Above I try to convert any letters into a number value
for i in range(0,len(decimal)):
converted_decimal=decimal[i]*(16**i)
total_decimal=converted_decimal+converted_decimal
return total_decimal
#Here I'm trying to add each converted decimal
int('0xA', 16)oreval('0xA')