52

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);

output should be equal to 5

Christopher Chiche
  • 15,075
  • 9
  • 59
  • 98

1 Answers1

121

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

int output = Convert.ToInt32(input, 2);
Heinzi
  • 167,459
  • 57
  • 363
  • 519