C Program to Convert Binary to Decimal number

Program to Convert Binary to Decimal number:Number System 

Output :

Note : 

This program is for beginners (not for Experts) that’s why we haven’t provided any Validations while accepting the input. Please provide proper binary input to this program i.e (0 and 1).

Logic of This Program :

In the main function we have accepted the proper binary input i.e suppose we have accepted 111 as binary input.

Inside the function while loop gets executed. Sample Dry run for the while loop is shown below –

Before Entering into Loop111Garbage00
After Iteration 111111
After Iteration 21132
After Iteration 30173

Algorithm for Binary to Decimal :

  1. Accept Number from User
  2. Divide Number by 10 and Store Remainder in variable rem
  3. Divide Original Number by 10.

Inside the First Iteration power = 0. Power is Incremented in each Iteration.

  1. Calculate sum using the above formula, calculated sum is nothing but the decimal representation of the given binary number.