Lesson 3 of 15
NAND & NOR Gates
NAND and NOR Gates
NAND is NOT-AND: it outputs 0 only when all inputs are 1.
NOR is NOT-OR: it outputs 1 only when all inputs are 0.
| A | B | NAND | NOR |
|---|---|---|---|
| 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
NAND and NOR are called universal gates — you can build any other gate using only NAND (or only NOR) gates.
In JavaScript, using bitwise operators:
// NAND(a, b) = NOT(AND(a, b))
(a & b) ^ 1
// NOR(a, b) = NOT(OR(a, b))
(a | b) ^ 1
Your Task
Implement nand(a, b) and nor(a, b), then print all four combinations for each.
JavaScript loading...
Loading...
Click "Run" to execute your code.