將任意進制轉換成十進制
print(int("54", 8)) # 表示把8進制的54轉換成十進制數並輸出結果。 # 8可以是2、8,10,16等進制數
將十進制轉換成任意進制
def f(n,x): #n為待轉換的十進制數,x為機制,取值為2-16 a=[0,1,2,3,4,5,6,7,8,9,'A','b','C','D','E','F'] b=[] while True: s=n//x # 商 y=n%x # 余數 b=b+[y] if s==0: break n=s b.reverse() for i in b: print(a[i],end='') f(44,8)
將十進制decimal system轉換成二進制binary system
print(bin(10))
將十進制decimal system轉換成八進制Octal
print(oct(10))
將十進制decimal system轉換成十六進制Hexadecimal
print(hex(10))