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
相關文章
相關標籤/搜索