# C Program for the Conversion of Binary to Decimal Number

Description:
Decimal Numbers:
Decimal numbers has a radix 10. Decimal numbers use a combination of 0,1,2,3,4,5,6,7,8,9.
Binary Numbers:
Binary numbers has a radix of 2. Binary numbers use a combination of 0’s and 1’s.
Conversion from binary number system to decimal number system can be done by multiplying the digits with 2 raised to the power of its position from left to right as the below

This code will work for binary numbers with 10 digits and only for integers, due to the data type restriction of C language.

Source Code:
/*
Binary to decimal conversion using C
Author: sourcecodesonline.blogspot.com
*/
#include<stdio.h>
int main(void)
{    unsigned long dec_no=0,bin_no,pow=1;
printf("\n\t\t\tBinary to decimal conversion");
printf("\n\tEnter the binary number\t:");
scanf("%ld",&bin_no);
while(bin_no!=0)
{
dec_no+=(bin_no%10)*(pow);
pow*=2;
bin_no/=10;
}
dec_no+=bin_no*pow;
printf("The decimal equivalent is %ld",dec_no);
Previous
Next Post » 