# Python Convert Decimal to Binary Octal Hexadecimal

By | July 27, 2020

### How this Program Works?

This Python program will perform number convertion using builtin Python functions.

It uses builtin Python functions for number system conversion:

1. bin(int_number)
2. oct(int_number)
3. hex(int_number) ## Python bin() Function

The Python bin() function converts an integer number to a binary string prefixed with 0b . For example, the binary equivalent of 2 is 0b10 .

## Python oct() Function

The oct() function converts an integer into an octal string.

Octal strings in Python are prefixed with 0o.

Example:

x = oct(12)

print(x)

Output: 0o14

## Python hex() Function

The hex() function converts the specified number into a hexadecimal value. The returned string always starts with the prefix 0x .

Example:

x = hex(255)
print(x)

Output: 0xff

## Source Code Python Convert Decimal to Binary, Octal, and Hexadecimal numbers

```# this Python program converts a given
# decimal number to corrsponding
# numbers using builtin functions

dec = int(input("Enter a decimal number: "))

print(bin(dec),"in binary.")
print(oct(dec),"in octal.")
```
```Sample Run Output:

Enter a decimal number: 9
0b1001 in binary.
0o11 in octal.