How to implement a xor gate with nand gates

boolean-algebradigital-logic

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.

Best Answer

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:

schematic

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.