06-21-2003, 08:23 AM
Circuit construction, adder circuits use a XOR gate for the sum value. ie.
Sum(S) = A XOR B, and Carry© = A AND B. Although at circuit construction level usually NAND gates are used for implementation because all other gates can be constructed using just NANDs which reduces cost.
Bitflipping, as mentioned by Seph. Taking a n-bit number and XORing it against a value where all the bits are set will flip all the bits in the number.
Anytime you need to determine if one or the other, but not both of two values is set. Although many programmers will simply write this long hand:
You will probably find many examples of code that are actualling using exclusive-or logic without using the operator directly.
Code:
A B | S C
----+----
0 0 | 0 0
0 1 | 1 0
1 0 | 1 0
1 1 | 0 1
Bitflipping, as mentioned by Seph. Taking a n-bit number and XORing it against a value where all the bits are set will flip all the bits in the number.
Anytime you need to determine if one or the other, but not both of two values is set. Although many programmers will simply write this long hand:
Code:
if A then
if not B then ...
else
if B then ...
end if
esus saves.... Passes to Moses, shoots, he scores!