代码实现
def scale(number, decimal_str="01"):
"""
转换十进制成为任意进制数值,进制字母可自定义
:param number: 十进制数值
:param decimal_str: 默认数值字符是01,也就是说默认是转换成传统二进制数值
:return: 进制转换后的数值字符串
"""
alphabet = list(decimal_str)
decimal = len(alphabet)
output = ""
while number != 0:
number, digit = divmod(number, decimal)
output += alphabet[digit]
if output is "":
output = alphabet[0]
return output[::-1]
print(scale(9))
网友评论