0

I'm trying to do the "Xor" operation. Firstly i convert two strings into binary, i loop on each character of the first ch in first string and the second string to xor them together, but i keep getting "overflow exception was unhandled by the user code"

r1 = 0; r2 = 0; s1 = ""; s2 = "";
  //lastW    ="10001011100001001110101100000001"

            r1 = int.Parse(lastW); //Here where i get the exception

I tried also using

 r1 = Convert.ToInt32(lastW);

but i get the same exception

1 Answers1

0

Your string holds a number slightly larger than "ten nonillion" in base 10. That's quite a lot larger than the maximum value of an int32.

You can use Convert.ToInt32(lastW, 2) to convert from a binary string (the second optional parameter of Convert.ToInt32 accepts a radix from which to convert).

Arcanox
  • 1,420
  • 11
  • 20