【问题标题】:Convert binary string into integer将二进制字符串转换为整数
【发布时间】:2012-02-27 07:33:41
【问题描述】:

我想将写入字符串中的二进制数转换为其整数值。

例如:

string input = "0101";
int output = convert(input);

output 应该等于5

【问题讨论】:

  • 你应该在询问之前尝试谷歌搜索“C# convert X to Y”。
  • Binary String to Integer 的可能重复项
  • @TimLloyd 另一个问题较新?如果有什么问题是这个问题:)
  • @mhvelplund 我链接到的问题是在“2009 年 8 月 13 日”提出的。

标签: c# .net string binary


【解决方案1】:

Convert.ToInt32(String, Int32) 让您指定基数:

int output = Convert.ToInt32(input, 2);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-16
    • 2017-04-25
    • 1970-01-01
    • 2021-02-24
    相关资源
    最近更新 更多