Write a Python Program to Convert Decimal to Binary, octal, and Hexadecimal with an example. In this Python example, we used the bin (converts to binary), oct (for octal), and hex (for hexadecimal) functions.
decimal = int(input("Please Enter the Decimal Number = "))
binary = bin(decimal)
octal = oct(decimal)
hexadecimal = hex(decimal)
print(decimal, " Decimal = ", binary, "Binary Value")
print(decimal, " Decimal = ", octal, "Octal Value")
print(decimal, " Decimal = ", hexadecimal, "Hexadecimal Value")

The following program uses the format() function to convert decimal values to binary, octal, and hexadecimal values. Here, {0:b} represents binary, {0:o} represents octal, and {0:x} means hexadecimal. Refer to Python string format.
d = int(input("Enter Decimal Value = "))
print("Binary = {0:b}".format(d))
print("Octal = {0:o}".format(d))
print("Hexadecimal = {0:x}".format(d))
Enter Decimal Value = 22
Binary = 10110
Octal = 26
Hexadecimal = 16
Also Read