C# 将二进制字符串转换为整数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9149728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 06:10:21  来源:igfitidea点击:

Convert binary string into integer

c#.netstringbinary

提问by Christopher Chiche

I would like to convert a binary number writen in a String into its integer value.

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

For example:

例如:

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

outputshould be equal to 5

output应该等于 5

采纳答案by Heinzi

Convert.ToInt32(String, Int32)lets you specify the base:

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

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