Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the | and ^ operators used for? [duplicate]

Tags:

operators

c#

.net

Possible Duplicate:
What are bitwise operators?

Recently I came across a few samples that used the | and ^ operator. I am guessing these are or and negation operators.

So what actually do these operators stands for?

like image 719
Simsons Avatar asked Sep 17 '10 13:09

Simsons


2 Answers

  • | = (bitwise/non-short-circuiting) "or"
  • ^ = "xor"

and for info, "not" (bitwise negation) is ~

like image 159
Marc Gravell Avatar answered Oct 12 '22 19:10

Marc Gravell


If you apply it to integral types, they are bitwise or and xor operator. However if you apply them to boolean types, they are logical or and xor. Look at an explanation of or operator and xor operator

You can get more details on boolean operations from the wikipedia truth table

like image 32
Andrea Parodi Avatar answered Oct 12 '22 18:10

Andrea Parodi