Fork me on GitHub

python十分简单实现十进制到任意进制的转换

 1 def ten_to_sixteen(n,x):
 2     a=[0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F']
 3     b=[]
 4     while True:
 5         s = n //x
 6         y = n % x
 7         b = b+[y]
 8         if s == 0:
 9            break
10         n = s
11     b.reverse()
12     for i in b:
13         print(a[i],end="")
14 
15 mm=ten_to_sixteen(10240,16)
View Code

 

posted on 2019-06-05 17:57  vmaze  阅读(711)  评论(0编辑  收藏  举报

导航