## Question Reference

Python Home

### Python Methods

Python String Methods

### Python Interview Programs

Python Common ProgramsPython Array ProgramsPython Converter ProgramsPython Star Patterns ProgramPython Number Patterns ProgramPython Alphabet Patterns Program

ASCII Table

# Python Program to Converter a Decimal to Binary

Last Updated:

## Converter a Number from Decimal to Binary

In the following example, we will convert a Decimal Number (500) to Binary Number (111110100).

Tips: It is recommended to use our online Decimal to Binary calculator for better understanding.

### Example

Python Compiler
import math num = 500 arr = [0]*50 i = -1 while(num != 0): i += 1 arr[i] = num % 2 num = math.floor(num / 2) print("Binary number of 500 (decimal) is ", end="") for j in range(i, -1, -1): print(arr[j], end="")

## Converter any Given Decimal Number to Binary Number

In the following example, we will convert any given decimal number to a binary number.

### Example

Python Compiler
import math num = int(input("Enter a Decimal Number: ")); copyNum = num; arr = [0]*50 i = -1 while(copyNum != 0): i += 1 arr[i] = copyNum % 2 copyNum = math.floor(copyNum / 2) print("Binary number of %d (decimal) is " % num, end="") for j in range(i, -1, -1): print(arr[j], end="")