
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to 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.
- Related Articles
- How to convert a Decimal to Octal using C#?
- How to Convert Decimal to Octal?
- How to Convert Decimal to Hexadecimal?
- How to Convert Hexadecimal to Decimal?
- Convert Hexadecimal to Octal in Java?
- JAVA Program to Convert Octal to Hexadecimal
- How to Convert Binary to Octal?
- How to Convert Decimal to Binary Using Recursion in Python?
- How to Convert Binary to Hexadecimal?
- Python program to convert float decimal to octal number
- How to Convert Octal to Binary?\n
- How do we convert binary to decimal and decimal to binary?
- How to convert Decimal to Binary using C#?
- How to convert Decimal to Hexadecimal in Java
- Program to Convert Hexadecimal to Octal in C program

Advertisements