Given a decimal number as input, we need to write a program to convert the given decimal number into equivalent binary number.
Input : 7 Output :111 Input :10 Output :1010
We have discussed one iterative solution in below post.
Program for Decimal to Binary Conversion
Below is Recursive solution
findBinary(decimal) if (decimal == 0) binary = 0 else binary = decimal % 2 + 10 * (findBinary(decimal / 2)
Step by step process for better understanding of how the algorithm works
Let decimal number be 10.
Step 1-> 10 % 2 which is equal-too 0 + 10 * ( 10/2 ) % 2
Step 2-> 5 % 2 which is equal-too 1 + 10 * ( 5 / 2) % 2
Step 3-> 2 % 2 which is equal-too 0 + 10 * ( 2 / 2 ) % 2
Step 4-> 1 % 2 which is equal-too 1 + 10 * ( 1 / 2 ) % 2
- Python program to covert decimal to binary number
- Program for Binary To Decimal Conversion
- Recursive Program for Binary to Decimal
- Program for Decimal to Binary Conversion
- Decimal representation of given binary string is divisible by 10 or not
- Decimal to binary conversion without using arithmetic operators
- Decimal representation of given binary string is divisible by 20 or not
- Binary to decimal and vice-versa in python
- Binary to Gray code using recursion
- Leaf nodes from Preorder of a Binary Search Tree (Using Recursion)
- Sum of digit of a number using recursion
- Check if Decimal representation of an Octal number is divisible by 7
- Converting Decimal Number lying between 1 to 3999 to Roman Numerals
- Program to Convert Octal Number to Binary Number
- Convert a binary number to hexadecimal number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : jit_t