# Decimal to Binary Conversion

“** Decimal to Binary Conversion**” is one of the classic programming problem exercise for beginners. Here, we are given a decimal number, entered by user and our task is to write a program to convert the given decimal number to its equivalent binary number.

**Example:**

7 -> 111 3 -> 11 8 -> 1000

The steps to convert the decimal number to binary are as follows:

- Take Binary = 0, iterator = 1.
- Store the remainder when the decimal number is divided by 2.
- Divide the decimal number by 2.
- Binary = Binary + iterator * remainder.
- Multiply the iterator by 10.
- Repeat the steps from 2 to 5 until decimal number is not 0.
- Print the Binary Number.

**C++ Program to convert Decimal to Binary is as follows:**

/* C++ Program to Convert Decimal Number to Binary Number */ #include<bits/stdc++.h> using namespace std; int main() { /* Scan the Decimal Number */ int Decimal; cout<<"Enter the Decimal Number: "; cin>>Decimal; /* Converting Decimal to Binary */ int Binary = 0; int iterator = 1; int temp = Decimal; while(temp != 0) { int remainder = temp % 2; temp = temp / 2; Binary = Binary + remainder*iterator; iterator = iterator * 10; } /*Printing the result */ cout<<"The Binary of "<<Decimal<<" is "<<Binary; }

Enter the Decimal Number: 7 The Binary of 7 is 111OUTPUT:

**Related Posts:**

**Program to convert decimal number to octal number.****Program to convert decimal number to hexadecimal number.****Program to convert hexadecimal number to binary number.****Program to convert hexadecimal number to octal number.****Program to convert hexadecimal number to decimal number.****Program to convert binary number to octal number.****Program to convert binary number to decimal number.****Program to convert binary number to hexadecimal number.****Program to convert octal number to binary number.****Program to convert octal number to decimal number.****Program to convert octal number to hexadecimal number.****Program to check Leap Year.****Program to find sum of first ‘n’ natural numbers.****Program to Reverse a Number.****Program to swap two Numbers.****Program to print Fibonacci Series up to Nth Term.****Program to find and print nth Fibonacci number.****Program to find Power of the Number.****Program to find Quotient and Remainder.****Program to find largest amongst three numbers.**