实现进制转化伪代码
伪代码
Write "Enter the new base"
Read newBase
Write "Enter the number to be converted"
Read decimalNumber
Set quotient to 1
WHILE (quotient is not zero)
Set quotient to decimalNumber DIV newBase
Set remainder to decimalNumber REM newBase
Make the remainder the next digit to the left in the answer
Set decimalNumber to quotient
Write "The answer is "
Write answer
用python编写的程序
# coding=utf-8
#实现进制转化伪代码
newBase = int( input('Enter the new base: ')) #输入想要转换的进制
decimaNumber = int(input('Enter the nember to be converted: ')) #转换的数字
quotient = 1
m = {10:'A',11:'B',12:'C',13:'D',14:'E',15:'F'} #用作16进制转换
b = []
while quotient != 0:
quotient = decimaNumber // newBase
remainder = decimaNumber % newBase
if remainder > 9:
remainder = m[remainder]
b.append(remainder)
decimaNumber = quotient
b.reverse()
for a in b:
print(a,end="")
运行结果
(有二进制,八进制,十六进制)