Python Program to Convert Decimal to Binary, Octal and Hexadecimal


Example

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


Output

enter a decimal number: 15

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


Explanation

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.