0

I am experimenting with the compound assignment operators and I understand how they work with boolean types but I do not understand how things work with integers or characters.

I know that this is not useful, I am just experimenting. So I have this integer that has the value of 10 and whenever I do the following, it outputs 12 but I do not know why. Please help me.

int oppo = 10;
Console.WriteLine(oppo^=6);
Eric Movsessian
  • 488
  • 1
  • 11
  • Is your question about integer vs character vs boolean, or is it about compound vs simple operator, e.g. `Console.WriteLine(oppo^=6);` vs `oppo^=6; Console.WriteLine(oppo);` vs `Console.WriteLine(oppo ^ 6);` Because an explanation about compound assignment will tell you nothing about the different data types, and vice versa, they are two totally different questions. – Ben Voigt Apr 08 '22 at 21:26
  • No, I am trying to understand when doing this Console.WriteLine(oppo^=6); why does it output 12. – Eric Movsessian Apr 08 '22 at 21:27
  • 3
    @EricMovsessian `b1010` (`10`) XOR `b0110` (`6`) results in `b1100`, which is `12`. What exactly is the question? – Progman Apr 08 '22 at 21:28
  • 1
    That's easily explained by looking at XOR: `int x = 10 ^ 6; Console.WriteLine(x);` Has nothing to do with a compound assignment. – Ben Voigt Apr 08 '22 at 21:28
  • https://stackoverflow.com/a/276724/103167 – Ben Voigt Apr 08 '22 at 21:32
  • Okay thanks, sorry about the question, did not think deeply enough. – Eric Movsessian Apr 08 '22 at 21:33

0 Answers0