C / C++ / C#

  1. Home
  2. Computing & Technology
  3. C / C++ / C#

Definition of XOR

By David Bolton, About.com

Definition: XOR is a binary operation like AND and OR. If two bits are XORed together the results are as follows.

A B --- A XOR B
0 0 ----- 0
0 1 ----- 1
1 0 ----- 1
1 1 ----- 0
Another way to express this is that the result is true if they are different or false if they are not the same..

Useful Property

Mathematically, XOR is both associative and commutative. What this means is that if
C = A xor B
then
B = C xor A or
B = A xor C
and
A = B xor C
A = C xor B
This can be used to disguise text.
'A' xor 0x5516 = 0x1416
By Xoring this value with 0x5516 again the original value 'A' is recovered.

In C, C++ and C# binary XOR is represented by a single character ^.

int c = a^b;

Glossary:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Alternate Spellings: Exclusive OR

Explore C / C++ / C#

About.com Special Features

C / C++ / C#

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. Glossary
  5. XOR - Definition

©2009 About.com, a part of The New York Times Company.

All rights reserved.