我正在尝试编写一个将十六进制转换为十进制的函数。我有两个问题。我无法用数字替换所有字母。它替换了一个字母,然后停止。其次,我如何得到它以便它连续添加每个整数?
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