;

Python Program to Convert Decimal to Binary, Octal and Hexadecimal


Tutorialsrack 22/04/2020 Python

In this Python program, we will learn how to convert decimal to binary, decimal to octal and decimal to hexadecimal number. For Converting decimal to binary, decimal to octal and decimal to hexadecimal, we will use the bin() function for conversion from decimal to binary and oct() function for conversion from decimal to octal and hex() function for converting decimal to hexadecimal numbers.

Here is the code of the program to convert decimal to binary, decimal to octal and decimal to hexadecimal number.

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

# To take the input from the user
DecNum = int(input("Enter the Decimal Number: "))

print("The decimal value of", DecNum, "is: \n")
print(bin(DecNum), "in binary.")
print(oct(DecNum), "in octal.")
print(hex(DecNum), "in hexadecimal.")
Output

Enter the Decimal Number: 55

The decimal value of 55 is: 

0b110111 in binary.

0o67 in octal.

0x37 in hexadecimal.


Related Posts



Comments

Recent Posts
Tags