-1

I have this binary string

string binary = "10101010";(8 bit) and I want to have the same number as a a decimal. I don't know lot of functions in c# and I think It's will be much faster to ask It here.

Here the result in decimal of "10101010" is 170, do you know a function in c# that could help me do it?

heya
  • 11
  • 2
  • Do you know what is faster than asking here (typing out your question, making it clear, and then waiting for someone to type an answer)? Putting your title in the search box and finding an existing question and correct answer. – Ben Voigt Apr 20 '20 at 20:24

1 Answers1

6

According to documentation Convert.ToInt32 function allows you to specify the base for conversion for numbers, e.g. if you want to convert number from binary to decimal you can invoke method with 2 value as a base:

string binary = "10101010"
int output = Convert.ToInt32(binary , 2);
elvira.genkel
  • 1,303
  • 1
  • 4
  • 11