c# - 将基数 2 转换为基数 10

标签 c#

我正在尝试将基数 2 转换为基数 10,但我不断收到:

"Value was either too large or too small for an Int64".

我使用此代码:

string number1 = Convert.ToString(Convert.ToInt64(numberBin1, 10));    

即使使用合理的值,它也会显示错误,例如:000111110100111101010000

编辑:感谢 Johnny 和 JSteward 修复

最佳答案

ToInt64 方法的第二个参数是 fromBase,在您的情况下它应该是 2。

long number = Convert.ToInt64("000111110100111101010000", 2));

关于c# - 将基数 2 转换为基数 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54597842/

相关文章:

C# 将列表与自定义对象进行比较但忽略顺序

c# - CSV 文件中的新行

c# - WPF ListView GridView 单元格样式和绑定(bind)

c# - gameObject.Destroy() 会删除列表中的引用游戏对象吗?

c# - 在客户端计算机上安装字体

用于创建可选属性的 C# 接口(interface)

c# - 如何在Windows窗体应用程序C#中使用超链接属性

c# - 将复选框控件添加到列表框

c# - 如何在 HtmlAgilityPack 中使用代理

c# - MVC 5 - Controller 看不到我需要的命名空间