🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X
Questions




































Python Program to Convert Decimal to Binary, Octal and Hexadecimal

Last Updated : 18 Jul 2025 Jul 24, Jan 24

Solution:

# Get a number from the user
num = int(input("Enter a number: "))

# Print the binary representation
print("Binary:", bin(num))

# Print the octal representation
print("Octal:", oct(num))

# Print the hexadecimal representation
print("Hexadecimal:", hex(num))

 

OUTPUT:
Enter a number: 13
Binary: 0b1101
Octal: 0o15
Hexadecimal: 0xd

 

Explanation:

  • Input: Read an integer from the user.
  • Conversions:
    • bin(num): Binary format (prefix 0b).
    • oct(num): Octal format (prefix 0o).
    • hex(num): Hexadecimal format (prefix 0x).
  • Output: Prints the number in binary, octal, and hexadecimal formats.
Report an error

Meanwhile you can watch this video

Watch Video
Latest Updates