BINARY TO DECIMAL.

 Binary To Decimal.

111001
explanation:
1           1               1              0               0             1     1*2^5¦1*2^4¦1*2^3¦0*2^2¦0*2^1¦1*2^0

#include<stdio.h>
#include<math.h>
int main()
{
    int n,i=0,decimal=0,rem;
    printf("enter binary number :");
    scanf("%d",&n);
    while(n>0)
    {
        rem=n%10;
        n=n/10;
        decimal+=rem*pow(2,i);
        i++;
    }
    printf("decimal = %d",decimal );
    return 0;
}

OUTPUT :

enter binary number :111001
decimal = 57

Comments