Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge: Identify ways to use XOR logical operator
#5
Circuit construction, adder circuits use a XOR gate for the sum value. ie.
Code:
A B | S C
----+----
0 0 | 0 0
0 1 | 1 0
1 0 | 1 0
1 1 | 0 1
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:
Code:
if A then
  if  not B then ...
else
  if B then ...
end if
You will probably find many examples of code that are actualling using exclusive-or logic without using the operator directly.
esus saves.... Passes to Moses, shoots, he scores!
Reply


Messages In This Thread
To Seph: - by Moneo - 06-21-2003, 07:41 AM
Challenge: Identify ways to use XOR logical operator - by LooseCaboose - 06-21-2003, 08:23 AM
To LooseCaboose: - by Moneo - 06-21-2003, 08:59 AM
To drV: - by Moneo - 06-21-2003, 09:24 AM
Re: To drV: - by DrV - 06-21-2003, 09:39 AM
To Toonski84 - by Moneo - 06-21-2003, 10:03 AM
Re: To drV: - by relsoft - 06-22-2003, 02:20 PM
Sample reason for using XOR. - by Moneo - 06-23-2003, 09:33 PM
Update: - by Moneo - 07-03-2003, 11:32 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)