gpt4 book ai didi

c# - 将大二进制字符串转换为十进制字符串

转载 作者:太空宇宙 更新时间:2023-11-03 17:26:48 25 4
gpt4 key购买 nike

我有一个大文本,包含一个数字作为二进制值。例如“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();
}

关于c# - 将大二进制字符串转换为十进制字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8774083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com