python小程序
1.10进制转任意进制:
def decimalToNBaseByNormal(decimalVar, base):
tempList = []
temp = decimalVar
i = 0
while (temp > 0):
ord = temp % base
if (ord > 9): #如果余数大于9,则以字母的形式表示
ord = chr(65 + (ord - 10)) #把数字转换成字符
tempList.append(ord)
temp = int(temp / base)
i = i + 1
tempList.reverse();
#print(tempList)
binary = “”
for j in range(len(tempList)):
binary = binary + str(tempList[j]);
print(“the decimal is: %d and after convering by %d base is %s”%(decimalVar, base, binary))
st = decimalToNBaseByNormal(-41,3)