Convert binary string into integer

C#.NetStringBinary

C# Problem Overview


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

C# Solutions


Solution 1 - C#

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

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChristopher ChicheView Question on Stackoverflow
Solution 1 - C#HeinziView Answer on Stackoverflow