Answers for "binary to octal in python"

3

octal in python

# Python program to convert decimal into other number systems
dec = 344

print("The decimal value of", dec, "is:")
print(bin(dec), "in binary.")
print(oct(dec), "in octal.")
print(hex(dec), "in hexadecimal.")
Posted by: Guest on July-06-2020
0

binary to octal in python

==== 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 <class 'int'>

octalNum = oct(decimalNum)[2:]  # base 10 to base 8
print(octalNum, type(octalNum))  # 314 <class 'str'>
Posted by: Guest on September-22-2021

Python Answers by Framework

Browse Popular Code Answers by Language