on
Italy
- Get link
- X
- Other Apps
60 = 0b11100 = 0o74 = 0x3c
# Python program to convert decimal number into binary, octal and hexadecimal number system
# Take decimal number from user
dec = int(input("Enter an integer: "))
print("The decimal value of",dec,"is:")
print(bin(dec),"in binary.")
print(oct(dec),"in octal.")
print(hex(dec),"in hexadecimal.")
OutputEnter an integer: 344 The decimal value of 344 is: 0b101011000 in binary. 0o530 in octal. 0x158 in hexadecimal.In this program, we have used built-in functions
bin()
, oct()
and hex()
to convert the given decimal number into respective number systems.
These functions take an integer (in decimal) and return a string.
Comments
Post a Comment