Is the ^ operator really the XOR operator in C#?

20,512

It is not the power of operator of C# since there is no such operator in C#. It is just the XOR operator.

For "power of", use Math.Pow.

As you can see from this page on the C# Operators, ^ is listed under the "Logical (boolean and bitwise)" category, which means it can both handle boolean values, and binary values (for bitwise XOR).

Share:
20,512
RCIX
Author by

RCIX

Lua is underrated!

Updated on March 19, 2020

Comments

  • RCIX
    RCIX about 4 years

    I read that the ^ operator is the logical XOR operator in C#, but I also thought it was the "power of" operator. What is the explanation?

  • RCIX
    RCIX over 14 years
    hmm, then wherever i was using that operator as "power of" i'll have to fix at some point...
  • Michael Stum
    Michael Stum over 14 years
    Just to add: The PowerOf Function in C# is Math.Pow. msdn.microsoft.com/en-us/library/system.math.pow.aspx
  • LukeH
    LukeH over 14 years
    @RCIX: Didn't you notice any incorrect results when you were attempting to use ^ as the power-of operator?
  • Christian Hayter
    Christian Hayter over 14 years
    ^ is the "power of" operator in VB.NET.
  • user247702
    user247702 about 12 years
    @LukeH depends on the numbers you're working with I guess. I quickly noticed when my items with a height of 2 ^ 2 weren't visible.