Python Program to Convert Decimal to Binary, Octal and Hexadecimal

Spread the love

In this article, You will learn how to write python program to Convert Decimal to Binary, Octal and Hexadecimal
In python we have inbuilt functions bin(), Oct(), hex(). We write program with the help of those functions.

#Convert decimal to binary value

dec = 522 print("The binary value is",bin(dec))

Output:

The binary value is 0b1000001010

#Convert decimal to octal value

dec = 522 print("The Octal Value is",oct(dec))

Output:

The Octal Value is 0o1012
#Convert Decimal value to hexadecimal
dec = 522 print("The Hexdecimal Value is",hex(dec))

Output:

The Hexdecimal Value is 0x20a

 

admin

admin

Leave a Reply

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