

- 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
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 Questions & Answers
- 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
- Java program to convert decimal number to binary value
- Java program to convert binary number to decimal value
- Program to convert Linked list representing binary number to decimal integer in Python
- C++ program to Convert a Decimal Number to Binary Number using Stacks
- C# Program to Convert Binary to Decimal
- C# Program to Convert Decimal to Binary
- Convert decimal fraction to binary number in C++
- C++ Program to Convert Binary Number to Decimal and vice-versa
- Java Program to convert from decimal to binary
- Python program to convert float decimal to octal number
- Convert Decimal to Binary in Java
- C program to convert decimal fraction to binary fraction
Advertisements