ID:178601
 
I havn't ever messed with xor before, and I need someone to explain to me what it does, and a example snippet to show me how to use it.

Thanks in advance.

-Rcet
XOR (eXclusive OR) is a boolean algebra operator. It works in this manner:

FALSE XOR FALSE = FALSE
FALSE XOR TRUE = TRUE
TRUE XOR FALSE = TRUE
TRUE XOR TRUE = FALSE

Essentially, it returns TRUE if either, but not both, are TRUE (thats why its called exclusive or).

In programming, 1 represent TRUE and 0 represents FALSE, so you just have to apply the rule above to 1's and 0's.

Boolean operators aren't necessary very often, though. While its generally a good idea to learn them and be familiar with them, you don't really need it.

-AbyssDragon
Rcet wrote:
I havn't ever messed with xor before, and I need someone to explain to me what it does, and a example snippet to show me how to use it.

Thanks in advance.

Time for a little binary: When you use bitwise operators on a binary value, the bits are compared and you get a result based on the way the operator works. AND gives you 1 if both bits are 1; OR gives you 1 if either is 1. XOR is 1 only if the two are different.
    10101010
AND 00001111
= 00001010

10101010
OR 00001111
= 10101111

10101010
XOR 00001111
= 10100101

I hope that helps a little.

Basically XOR is used for things like toggling a bit flag on and off.

Lummox JR