十进制转换其他任意进制通用算法
# -*-coding=utf-8-*-
class Oton():
def __init__(self, num, n):
self.num = num # 十进制数
self.n = n # 转换为n进制
def translate(self):
str_temp = "" # 临时变量存储结果
while True:
if self.num >= self.n:
str_temp += str(self.num % self.n)
self.num = self.num // self.n
else:
str_temp += str(self.num)
break
return str_temp[::-1] # 逆向输出
oton = Oton(19, 9)
print(oton.translate())