
- 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
Convert decimal to binary number in Python program
In this article, we will learn about the solution to the problem statement given below.
Problem statement − We are given a decimal number, we need to convert it into its binary equivalent.
There are two approaches to solve the given problem. Let’s see them one by one−
Recursive Approach
Example
def DecimalToBinary(num): if num > 1: DecimalToBinary(num // 2) print(num % 2, end = '') # main if __name__ == '__main__': # decimal input dec_val = 56 # binary equivalent DecimalToBinary(dec_val)
Output
111000
All the variables and functions are declared in the global scope shown in the figure above.
Using Built-In method
Example
def decimalToBinary(n): return bin(n).replace("0b", "") # Driver code if __name__ == '__main__': print(decimalToBinary(56))
Output
111000
All the variables and functions are declared in the global scope shown in the figure above.
Conclusion
In this article, we have learned about the python program to convert a list into a string.
- Related Articles
- Python program to convert decimal to binary number
- Java Program to convert binary number to decimal number
- C++ Program To Convert Decimal Number to Binary
- Program to convert Linked list representing binary number to decimal integer in Python
- Java program to convert decimal number to binary value
- Java program to convert binary number to decimal value
- Haskell program to convert a decimal number into a binary number
- C++ program to Convert a Decimal Number to Binary Number using Stacks
- C++ Program to Convert Binary Number to Decimal and vice-versa
- Swift program to convert the decimal number to binary using recursion
- Haskell Program to convert the decimal number to binary using recursion
- Convert decimal fraction to binary number in C++
- C# Program to Convert Binary to Decimal
- Swift Program to convert Decimal to Binary
- Swift Program to convert Binary to Decimal

Advertisements