Python 十進制轉二進制、八進制、十六進制
# -*- coding: UTF-8 -*-
# Filename : test.py
# author by : www.runoob.com
# 獲取用戶輸入十進制數
dec = int(input("輸入數字:"))
print("十進制數爲:", dec)
print("轉換爲二進制爲:", bin(dec))
print("轉換爲八進制爲:", oct(dec))
print("轉換爲十六進制爲:", hex(dec))
結果輸出:
輸入數字:15
十進制數爲: 15
轉換爲二進制爲: 0b1111
轉換爲八進制爲: 0o17
轉換爲十六進制爲: 0xf