Lesson 5 of 15

Universal Gates

Universal Gates

NAND is called a universal gate because you can build any logic function using only NAND gates:

NOT(A)      = NAND(A, A)
AND(A, B)   = NAND(NAND(A, B), NAND(A, B))  = NOT(NAND(A,B))
OR(A, B)    = NAND(NAND(A, A), NAND(B, B))  = NAND(NOT(A), NOT(B))

This matters for chip manufacturing: a factory that can make NAND gates can make any digital circuit.

Let's verify De Morgan's law for NAND:

NAND(A, B) = NOT(A) OR NOT(B)

ABNANDNOT(A) OR NOT(B)
0011
0111
1011
1100

Your Task

Using only nand(a, b), implement:

  • notFromNand(a) — NOT using only NAND
  • andFromNand(a, b) — AND using only NAND
  • orFromNand(a, b) — OR using only NAND

Then print the full truth table for orFromNand.

JavaScript loading...
Loading...
Click "Run" to execute your code.