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

 

转载于:https://www.cnblogs.com/morgana/p/10981081.html

你可能感兴趣的:(python十分简单实现十进制到任意进制的转换)