二进制字符串转换为整数。整数、字符串、转换为

2023-09-02 10:41:03 作者:小不正经

我想转换writen在一个字符串到其整数值二进制数。

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

例如:

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

输出应等于 5

编辑:这真是小巫见大巫有人问,因为我有另外的错误,在我的code不使我看到,皈依是不是我的问题。

This really trivial question was asked because I had another bug in my code not enabling me to see that the convertion was not my problem.

推荐答案

Convert.ToInt32(字符串,的Int32 )允许您指定的基地:

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