将大的二进制字符串转换为十进制字符串

本文关键字:字符串 转换 十进制 二进制 | 更新日期: 2023-09-27 18:19:40

我有一个大文本,其中包含一个作为二进制值的数字。例如,"123"应为"001100010011001000110011"。编辑:应为1111011

现在我想把它转换成十进制,但这个数字对Int64来说太大了。

所以,我想要的是:将一个大的二进制字符串转换为十进制字符串。

将大的二进制字符串转换为十进制字符串

这样就可以了:

public string BinToDec(string value)
{
    // BigInteger can be found in the System.Numerics dll
    BigInteger res = 0;
    // I'm totally skipping error handling here
    foreach(char c in value)
    {
        res <<= 1;
        res += c == '1' ? 1 : 0;
    }
    return res.ToString();
}