Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Convert Decimal to Binary, Octal and Hexadecimal using Python



Python provides straightforward functions to convert Decimal to Binary, Octal, and Hexadecimal. These functions are −

Binary: bin()
Octal: oct()
Hexadecimal: hex()

Example

You can use these functions as follows to get the corresponding representation −

decimal = 27

print(bin(decimal),"in binary.")
print(oct(decimal),"in octal.")
print(hex(decimal),"in hexadecimal.")

Output

This will give the output −

0b11011 in binary.
0o33 in octal.
0x1b in hexadecimal.
Updated on: 2020-03-05T10:38:46+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements