Chris wrote:
Hi,
Can someone explain the use of XOR?
Thanks
I'm not sure what exactly you mean but one interesting use is in (very
simple) encryption (and decryption with the same key).
int secret = number ^ code; // encrypt word (or number) with a code
int notSecret = secret ^ code; // now notSecret has the same value as
the original number
It also describes the operation of a two-way light switch - you know the
type where you have a long room with one light and two switches (a
switch at either end). Either can turn on the light and then either can
turn it off. (Draw a picture if you don't get it).
I guess you are aware of the definition (from online help):
Binary ^ operators are predefined for the integral types and bool. For
integral types, ^ computes the bitwise exclusive-OR of its operands. For
bool operands, ^ computes the logical exclusive-or of its operands; that
is, the result is true if and only if exactly one of its operands is true.
Eddie