- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Decimal to binary list conversion in Python

Python being a versatile language can handle many requirements that comes up during the data processing. When we need to convert a decimal number to a binary number we can use the following python programs.

## Using format

We can Use the letter in the formatter to indicate which number base: decimal, hex, octal, or binary we want our number to be formatted. In the below example we take the formatter as 0:0b then supply the integer to the format function which needs to get converted to binary.

## Example

Dnum = 11 print("Given decimal : " + str(Dnum)) # Decimal to binary number conversion binnum = [int(i) for i in list('{0:0b}'.format(Dnum))] # Printing result print("Converted binary list is : ",binnum)

## Output

Running the above code gives us the following result −

Given decimal : 11 Converted binary list is : [1, 0, 1, 1]

## Using bin

The bin() is a in-built function which can also be used in a similar way as above. This function Python bin() function converts an integer number to a binary string prefixed with 0b. So we slice the first two characters.

## Example

Dnum = 11 print("Given decimal : " + str(Dnum)) # Decimal to binary number conversion binnum = [int(i) for i in bin(Dnum)[2:]] # Printing result print("Converted binary list is : ",binnum)

## Output

Running the above code gives us the following result −

Given decimal : 11 Converted binary list is : [1, 0, 1, 1]

- Related Questions & Answers
- Decimal to Binary conversion
- C Program for Decimal to Binary Conversion?
- Decimal to Binary conversion using C Programming
- Program for Binary To Decimal Conversion in C++
- Program for Decimal to Binary Conversion in C++
- Decimal to binary conversion using recursion in JavaScript
- Program to convert Linked list representing binary number to decimal integer in Python
- Decimal to Multiple-Bases Conversion with Stack
- Binary to decimal and vice-versa in Python
- Convert decimal to binary number in Python program
- Binary to BCD conversion in 8051
- BCD to binary conversion in 8051
- Implicit conversion from Int16 to Decimal in C#
- Implicit conversion from Char to Decimal in C#
- Implicit conversion from UInt64 to Decimal in C#