Here you will get python program to convert decimal to binary, octal and hexadecimal.
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.
Below program demonstrates that how we can do these conversions.
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
num = int(input("enter a decimal number: ")) print("\nbinary form is ", bin(num)) print("octal form is ", oct(num)) print("hexadecimal form is ", hex(num))
Output
enter a decimal number: 11
binary form is 0b1011
octal form is 0o13
hexadecimal form is 0xb
Comment below if you have any queries regarding above program.
how to print in octal without the small letter o in it like 013