# What is mean by this in C# x = y ^ x ^x;

• ### Question

•   x = y ^ x ^x;
Friday, September 3, 2010 1:21 PM

### All replies

• Hi,

the ^ is the xor operator.
All C# Operators can be found at http://msdn.microsoft.com/en-us/library/6a71f45d.aspx
The ^ operator can be found at http://msdn.microsoft.com/en-us/library/zkacc7k1.aspx

And that expression does not make sense in my eyes: x ^ x is always 0. So you have y ^ 0 which is simply y inverted.

a ^ b =  (a^b)
0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 0 = 1
1 ^ 1 = 0

With kind regards,

Friday, September 3, 2010 1:39 PM
• Hi,

And that expression does not make sense in my eyes: x ^ x is always 0. So you have y ^ 0 which is simply y inverted.

you almost got it right, if you look at your table you'll see that 0^0 = 0 and 1^0 = 1 so y^0 = y. not y inverted, the formulat still doesn't make sense though :)
Friday, September 3, 2010 2:19 PM
• Ahh yes, You are right of course. Thank you for the correction!
Friday, September 3, 2010 2:22 PM
• the formulat still doesn't make sense though :)

Unless the operator is overloaded. We don't know what types are x and y.
Friday, September 3, 2010 2:54 PM
• given the topic starter had no idea what ^ did, the odds of him having overloaded the operator, rather small but hey definitly not zero could be someone elses code.
Friday, September 3, 2010 3:33 PM
• ,

If your question has been solved, please don’t forget mark/vote the replies which helped you, this will encourage the other community members to join in discussion and help each one.

If there’s anything unclear, please feel free to let me know. And I’m glad to help you.

Have a nice day!

Mike

Tuesday, September 7, 2010 10:56 AM