Convert Decimal to Binary, Octal, and Hexadecimal in Python

(Last Updated On: 25/11/2022)

Python Program to Convert Decimal to Binary, Octal, and Hexadecimal

# Convert Decimal to Binary, Octal and Hexadecimal in python

# entered value will be converted to int from string
num=int(input("Enter the number: "))

print("The decimal value of", num, "is:")

# used built-in functions bin()
print(bin(num), "in binary.")

# used built-in functions oct()
print(oct(num), "in octal.")

# used built-in functions hex()
print(hex(num), "in hexadecimal.")

Output:

Enter the number: 1
The decimal value of 1 is:
0b1 in binary.
0o1 in octal.
0x1 in hexadecimal.

Leave a Reply

Your email address will not be published. Required fields are marked *