Answers for "converting binary to octal in python"

0

converting binary to octal in python

biNum = '1010'
print(oct(int(biNum, 2))[2:])
Posted by: Guest on September-22-2021
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

Code answers related to "converting binary to octal in python"

Python Answers by Framework

Browse Popular Code Answers by Language