# How to implement a xor gate with nand gates

I try to resolve a problem, how to implement a xor gate with nand's gate.

A xor B = A'B + AB'

So, this becomes :

A xor B = A'B + AB' + AA' + BB' = A(A' + B') + B(A' + B') = (A + B)(A' + B') =

(with De Morgan apllied on the second term) = (A + B)(AB)' = ..... ?

In this point i am blocked. If someone can help me, please. Thank you.

• apply Demorgans law on first term as well. – Plutonium smuggler Mar 5 '15 at 8:05

You've got a good start. Just re-distribute the second term over the first:

(A + B)(AB)' = A(AB)' + B(AB)'

And then apply De Morgan to the whole thing:

A(AB)' + B(AB)' = ((A(AB)')'(B(AB)')')'

The Boolean expression gets to be a little hard to read, but it translates to the following circuit: simulate this circuit – Schematic created using CircuitLab

Note that the exact same network works if all of the NAND gates are changed to NOR gates, except that you get an XNOR gate — the output is high if the inputs are equal.

• Or maybe he could just use demorgans on (a + b) to give ( a'.b')', right where he left..? – Plutonium smuggler Mar 5 '15 at 15:43
• @Plutoniumsmuggler: How exactly does that help? Now you're left with creating A' and B', which requires two more inverters. – Dave Tweed Mar 5 '15 at 17:31
• Right. It only "Looks" simpler. As they say 'All that glitters isnt gold'. My apologies. – Plutonium smuggler Mar 5 '15 at 17:53