Algorithm to perform Binary to Decimal Conversion

[23771 views]




What is Decimal Number System?

A number system with a base 10 is known as decimal number system. Hence, decimal numbers are denoted with a base 10.

This number system consists of 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Each digit in the decimal system has a position and every digit is ten times more significant than the previous digit.
For example: (461)10 , (370)10 , (890)10 , (400)10 , etc.

What is Binary Number System?

A number system with a base 2 is known as binary number system. Hence, binary numbers are denoted with a base 2. It consists of two values: 0 and 1.

Each digit in this system is said to be a bit. For example: (110101)2, (10101101)2, (10000)2, (10)2, etc.

Algorithm to perform Binary to Decimal Conversion:

Step 1: Start Step 2: Read the binary number from the user, say ‘n’ Step 3: Initialize the decimal number, d=0 Step 4: Initialize i=0 Step 5: Repeat while n != 0: Step 5.1: Extract the last digit by: remainder = n % 10 Step 5.2: n = n/10 Step 5.3: d = d + (remainder * 2<sup>i</sup>) Step 5.4: Increment i by 1 Step 6: Display the decimal number, d Step 7: Stop

Explanation:

We will start off by taking the number to be converted as user input. The idea behind this conversion is to extract the last digit from the number one at a time and multiply it with 2 to the power of the number’s position. This process is repeated for all the digits of the number. After this, all these products are added and the final sum is the corresponding decimal number. Let us take a look at an example for better understanding:

Given binary number: (10110)2
Corresponding decimal number = (1*24) + (0*23) + (1*22) + (1*21) + (0*20)
= 16 + 0 + 4 + 2 + 0
= 22

Flowchart to perform Binary to Decimal Conversion:

Algorithm to perform binary to decimal conversion
Remove WaterMark from Above Flowchart

                 



Want to Learn How to write own Algorithm and Flowcharts



Want to test your logical skills in Algorithms?




Comments










Search Anything:

Sponsored Deals ends in





Technical Quizzes Specially For You:

Search Tags

    Binary to Decimal Conversion Algorithm

    Binary to Decimal Conversion Pseudocode

    How to Convert Binary number to Decimal algorithm