Given below is a c program to convert binary number to decimal.
Example :
1111 - Binary Number
101 - Binary Number
Links that you may find important :
http://www.wikihow.com/Convert-from-Binary-to-Decimal
http://www.binaryhexconverter.com/binary-to-decimal-converter
Code :
Example :
1111 - Binary Number
1 1 1 123x1 + 22x1 + 21x1 + 20 = 8+4+2+1 = 15
23 22 21 20
8 4 2 1
101 - Binary Number
1 0 122x1 + 21x0 + 20 = 4+0+1 = 5
22 21 20
4 2 1
Links that you may find important :
http://www.wikihow.com/Convert-from-Binary-to-Decimal
http://www.binaryhexconverter.com/binary-to-decimal-converter
Code :
#include <stdio.h>
#include <conio.h>
void main()
{
long int n,i=1,d=0,m=0,l=0;
clrscr();
printf("Enter binary number : ");
scanf("%ld",&n);
while(n>0)
{
m=(n%10);
n=(n/10);
l=m*i;
d=d+l;
i=i*2;
}
printf("Decimal equivalent is : %ld",d);
getch();
}
Output :
Enter binary number : 1111 Decimal equivalent is : 15Note : The program above has been tested using TurboCPP. Leave a comment if you feel the program is incorrect and/or has errors and/or if the program and its output don't match. Please report about broken links.