How to Convert Decimal to Binary, Octal, and Hexadecimal using Python?
Answers
Python Program to Convert Decimal to Binary, Octal and Hexadecimal. Decimal System: The most widely used number system is decimal system. This system is base 10 number system. In this system, ten numbers (0-9) are used to represent a number.
A Python program to convert Decimal to Binary, Octal and Hexadecimal number systems.
_________________________________________
# Python program to convert decimal number into binary, octal and hexadecimal number system
# We can change this value to check for different numbers
dec = 344
print("The decimal value of",dec,"is:")
print(bin(dec),"in binary.")
print(oct(dec),"in octal.")
print(hex(dec),"in hexadecimal.")
OUTPUT:
The decimal value of 344 is:
0b101011000 in binary.
0o530 in octal.
0x158 in hexadecimal.
A number with the prefix ‘0b’ is considered binary, ‘0o’ is considered octal and ‘0x’ as hexadecimal. For example:
60 = 0b11100 = 0o74 = 0x3c