Python Program to Convert Decimal to Binary, Octal and Hexadecimal


num = int(input("enter a decimal number: "))
binary form is ", bin(num))
print("octal form is ", oct(num))
print("hexadecimal form is ", hex(num))


enter a decimal number: 15

binary form is  0b1111
octal form is  0o17
hexadecimal form is  0xf


Python provides inbuilt functions for conversion of one number system to another. 

  • Convert decimal to binary using bin() function. In converted binary form 0b is present at the beginning.
  • Convert decimal to octal using oct() function. In converted octal form 0o is present at the beginning.
  • Convert decimal to hexadecimal using hex() function. In converted hexadecimal form 0x is present at the beginning.