# Quickly convert Decimal to other bases in Python

• Difficulty Level : Easy
• Last Updated : 05 Jul, 2017

Given a number in decimal number convert it into binary, octal and hexadecimal number. Here is function to convert decimal to binary, decimal to octal and decimal to hexadecimal.

Examples:

```Input : 55
Output : 55  in Binary :  0b110111
55 in Octal :  0o67

Input : 282
Output : 282  in Binary :  0b100011010
282 in Octal :  0o432
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

One solution is to use the approach discussed in below post.

Convert from any base to decimal and vice versa

Python provides direct functions for standard base conversions like bin(), hex() and oct()

 `# Python program to convert decimal to binary, ` `# octal and hexadecimal ` ` `  `# Function to convert decimal to binary ` `def` `decimal_to_binary(dec): ` `    ``decimal ``=` `int``(dec) ` ` `  `    ``# Prints equivalent decimal ` `    ``print``(decimal, ``" in Binary : "``, ``bin``(decimal)) ` ` `  `# Function to convert decimal to octal ` `def` `decimal_to_octal(dec): ` `    ``decimal ``=` `int``(dec) ` ` `  `    ``# Prints equivalent decimal ` `    ``print``(decimal, ``"in Octal : "``, ``oct``(decimal)) ` ` `  `# Function to convert decimal to hexadecimal ` `def` `decimal_to_hexadecimal(dec): ` `    ``decimal ``=` `int``(dec) ` ` `  `    ``# Prints equivalent decimal ` `    ``print``(decimal, ``" in Hexadecimal : "``, ``hex``(decimal)) ` ` `  `# Driver program ` `dec ``=` `32` `decimal_to_binary(dec) ` `decimal_to_octal(dec) ` `decimal_to_hexadecimal(dec) `

Output:

```32  in Binary :  0b100000
32 in Octal :  0o40