Program to Convert Decimal to Binary in C++ (vice versa)

 

1. Program to convert Decimal to Binary in C++

In this program, we will ask the user to enter the number which user wants to convert into binary.

Decimal to Binary Conversion Algorithm:

1 Step: At first divide the number by 2 by using modulus operator ‘%’ and store the remainder in the array.

2 Step: divide that number by 2.

3 Step: Now repeat the step until the number is greater than 0.

C++

Output:

program to convert decimal to binary in c++

2. Program to Convert Binary to Decimal in C++

In this program, we will convert the Binary input to Decimal.

Binary to Decimal Conversion Algorithm:

1 Step: Take a Binary Input to convert into Decimal.

2 Step: Multiply each binary digit starting from last with the power of 2 i.e(2^0,2^1).

3 Step: make an addition of the multiplied digits.

4 Step: Thus the addition gives the Decimal output.

C++

Output:

program to convert decimal to binary in c++

3. Decimal to Binary Conversion Using Bitwise Operator

C++

Output:

program to convert binary to decimal in c++

4. Decimal to Binary Without Using Array

C++

Output:

program to convert binary to decimal in c++

No comments