1# Python program to convert decimal into other number systems
2dec = 344
3
4print("The decimal value of", dec, "is:")
5print(bin(dec), "in binary.")
6print(oct(dec), "in octal.")
7print(hex(dec), "in hexadecimal.")
8
1 ==== Convert binary to octal in Python =====
2binaryNum = '11001100' # input a binary
3
4decimalNum = int(binaryNum, 2) # base 2 to base 10
5print(decimalNum, type(decimalNum)) # 204 <class 'int'>
6
7octalNum = oct(decimalNum)[2:] # base 10 to base 8
8print(octalNum, type(octalNum)) # 314 <class 'str'>