views:

280

answers:

5
(A Or B) And Not (A And B)
+19  A: 

You're looking for a XOR, depending on the language it may be a single operation.

Bryan McLemore
In your notation, that'd be: A Xor B
jeffamaphone
Should be optimized into a single operation by the compiler / interpreter, I would hope!
Jeff Paquette
My brain isn't working today.
ChaosPandion
Hehe, happens to us all mate.
Bryan McLemore
+3  A: 

If you have Xor or equality in your atomic operations, yes, it is exactly the former or the negation of the latter.

Pascal Cuoq
+3  A: 

isn't this just an exclusive or? sometimes indicated by this syntax: A ^ B

ennuikiller
I've never in my life seen that syntax. If you showed that to any logician they would say that that meant "A and B": XOR is usually written as a "+" inside an "O" or as a "=" with a "\" through it.
Satanicpuppy
That is the C based syntax which is indecently what I needed.
ChaosPandion
ennuikiller
+10  A: 
NawaMan
Nice trick for languages missing a native XOR operator.
Bryan McLemore
I agree, nice trick but I think it hides the intent of the expression.
ChaosPandion
!= is the right answer to this question. Simple and to the point.
Satanicpuppy
Not if there is a native XOR expression.
ChaosPandion
I agree, it's only valid if there isn't a XOR operator.
Bryan McLemore
A: 

As others have said, this is an XOR. Note that the best ways to solve this are either a logic table as NawaMan used, or with a Karnaugh map. In EE, Karnaugh maps are more common since they lend themselves more readily to complex expressions with multiple inputs.

If you're implementing this in hardware, Karnaugh maps are nearly always the best way to go as they give you the minimum number of gates required to implement the required outputs. Also, unlike in software, you may not have an xor gate available in hardware, but each gate can be expressed as a combination of other gates. AND can be made from NAND, etc, which will increase the number of gates required but can reduce the cost of your device.

David Lively