Binary to Decimal Conversion in C

The computer operates using binary, a base-2 number system consisting of only 0 and 1. However, for humans working with decimal numbers is easy which uses a base-10 system in this article we are going to write a C program for binary to decimal conversion.

Binary and Decimal System

Binary numbers represent values using powers of 2, where each digit is a power of 2 starting from the rightmost digit. while the decimal number system known as the base 10 system, is the standard system for integer and noninteger numbers. The decimal number system uses 10 digits- 0,1,2,3,4,5,6,7,8 and 9 to represent numerical values. In the decimal system, each digit position in a number is a power of 10.

Binary and Decimal Conversion Program in C

To convert binary numbers to decimal numbers we have to multiply each binary digit by the corresponding power of 2 and calculate the sum.

Output

Binary and Decimal Conversion Program in C

  • The above C program asks users to enter the binary number
  • After that program use a while loop to convert binary to decimal
  • In the while loop first staemnet extracts the right most digit by %10.
  • Next statement in the while loop multiply the remainder by the current base and add the result to a decimal number.
  • Value of base is update by base*2 and value of binary number is updated by binary number/2.
  • At the end, the program prints the decimal number.

Happy Coding

See Also

1 thought on “Binary to Decimal Conversion in C”

Leave a Comment