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))


The binary value is 0b1000001010

#Convert decimal to octal value

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


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


The Hexdecimal Value is 0x20a



Leave a Reply

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