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.

ABNANDNOR
0011
0110
1010
1100

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.