📜  python代码示例中的二进制到八进制

📅  最后修改于: 2022-03-11 14:45:49.556000             🧑  作者: Mango

代码示例1
==== Convert binary to octal in Python =====
binaryNum = '11001100'  # input a binary

decimalNum = int(binaryNum, 2)  # base 2 to base 10
print(decimalNum, type(decimalNum))  # 204 

octalNum = oct(decimalNum)[2:]  # base 10 to base 8
print(octalNum, type(octalNum))  # 314