A Program to Convert Decimal to Binary, Octal and Hexadecimal
In this example, we are giving a program to convert decimal to binary, octal and hexadecimal.
Program to convert decimal to binary, octal and hexadecimal:
# Convert decimal to binary, octal and hexadecimal
dec = int(input('Enter decimal number: '))
print("The decimal value of", dec, "is:")
print(bin(dec), "in binary.")
print(oct(dec), "in octal.")
print(hex(dec), "in hexadecimal.")
Output:
Enter decimal number: 10 The decimal value of 10 is: 0b1010 in binary. 0o12 in octal. 0xa in hexadecimal.