Python

Python Program to Convert Decimal to Binary, Octal and Hexadecimal1 min read

Write a program to Convert Decimal to Binary, Octal and Hexadecimal in Python

Code:




This Python program converts a decimal number (base 10) into binary (base 2), octal (base 8), and hexadecimal (base 16) number systems.

The program starts by prompting the user to input a decimal number and assigns it to the variable dec.

Then, the program uses three built-in functions: bin(), oct(), and hex() to convert the decimal number to binary, octal, and hexadecimal respectively. Each of these functions takes a single argument, the decimal number, and returns a string representation of the number in the desired base.

Finally, the program prints out the decimal value of the number entered, followed by the binary, octal, and hexadecimal equivalent of the number.

For example, if the user enters the decimal number 125, the output would be:

Leave a Comment