Why does the "^" symbol mean addition in C# in this case?

Just because I was curious, I did the simple Debug.Log line but instead of using “Debug.Log(Mathf.Pow())” I did “Debug.Log(2^24);” and the output was 26. I was confused so I did “Debug.Log(2^5);” to confirm what it was adding the numbers and the output was 7. Why does this happen?

In C#, the ^ is the bitwise exclusive-or (XOR) operator. I don’t think it’s often used in game programming. I know some languages use ^ as an exponent operator, so I guess that’s why you tried it. The numbers you used coincidentally returned a result equal to adding them. This happens if there are no matching on (1) bits in the binary representation of the two numbers.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms