程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python base conversion

編輯:Python
dec = int(input(" Input number :")) # Input 10
# Binary conversion 
res_bin = bin(dec)
# To octal 
res_oct = oct(dec)
# To hexadecimal 
res_hex = hex(dec)
print(" Convert decimal to binary :", res_bin) # 0b1010
print(" Decimal to octal to :", res_oct) # 0o12
print(" Decimal to hexadecimal is :", res_hex) # 0xa
print("=========== I'm a lovely divider ===============")
# int() Other decimal system to decimal system , The following number represents the number of hexadecimal conversion 
print(" Binary conversion to decimal results in :", int(res_bin, 2))
print(" Conversion from octal to decimal results in :", int(res_oct, 8))
print(" Conversion from hexadecimal to decimal results in :", int(res_hex, 16))


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved