C++ convert binary to decimal for bit values greater than 64 bits
<p>I am using this code to convert binary to decimal. But this code will not work for more 64 bits as __int64 holds only 8 bytes. Could you please tell suggest an algorithm to use to convert more than 64 bits to decimal values. Also my end result has to be string. Help is appreciated. Thanks.</p>

<pre><code> int bin2dec(char *bin)
 {
    __int64  b, k, m, n;
    __int64  len, sum = 0;

    len = strlen(bin) - 1;
    for(k = 0; k &lt;= len; k++)
    {
            n = (bin[k] - '0'); // char to numeric value
            if ((n &gt; 1) || (n &lt; 0))
            {
                    puts("\n\n ERROR! BINARY has only 1 and 0!\n");
                    return (0);
            }
            for(b = 1, m = len; m &gt; k; m--)
            {
                    // 1 2 4 8 16 32 64 ... place-values, reversed here
                    b *= 2;
            }
            // sum it up
            sum = sum + n * b;
    }
    return(sum);
 }
</code></pre>
