atecnal1838_con wrote:
>
> can any one help me please, in converting binary numbers to decimal in
> C.
>
>  
Here you go: this converts a binary string("1001011101") to a decimal 
value(605).

long Bin2Dec(const char *bin)
{
    long p = 0;
    long r = 0;
    long len = strlen(bin) - 1;
    for (long i = len; i >= 0; i--,p++)
    {
        if (bin[i] == '1')
            r += powf((float)2, (float)p);
    }

    return r;
}

Reply via email to