Sub topic 17
Logic Gates and Truth Tables
This chapter assumes you know how a transistor works as a switch (Transistor Structure and Action) and that you are comfortable with binary values 0 and 1. A logic gate is a circuit that takes one or more binary inputs and gives one binary output according to a fixed rule. Digital electronics is built from these gates, and JEE Main asks you to recognise them and complete their truth tables.
Binary signals and truth tables
In digital circuits, a voltage near the supply value is called HIGH (logic 1) and a voltage near zero is called LOW (logic 0). Each gate has a symbol and a Boolean expression. A truth table lists the output for every possible input combination. A gate with n inputs has 2^n rows.
The basic gates
- OR gives 1 if at least one input is 1. Expression: Y = A + B.
- AND gives 1 only if all inputs are 1. Expression: Y = A · B.
- NOT gives the opposite of its single input. Expression: Y = A'. It is also called an inverter.
The truth tables for these three gates are shown together.
| A | B | OR | AND | NOT A |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 0 |
Combined gates: NAND and NOR
NAND is AND followed by NOT. NOR is OR followed by NOT. Their outputs are the exact opposite of AND and OR.
| A | B | NAND | NOR |
|---|---|---|---|
| 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
Checking gates in code
The program below prints the truth table for all five two-input and one-input rules, so you can compare it with the tables above.
def and_(a, b):
return a & b
def or_(a, b):
return a | b
def not_(a):
return 1 - a
def nand(a, b):
return not_(and_(a, b))
def nor(a, b):
return not_(or_(a, b))
print("A B | AND OR NAND NOR | NOT A")
for a in (0, 1):
for b in (0, 1):
print(a, b, "|", and_(a, b), " ", or_(a, b), " ", nand(a, b), " ", nor(a, b), " |", not_(a))Reading a gate from a truth table
To identify an unknown gate, look at the row where the inputs are both 0 and the row where they are both 1.
- Output 0 for (0,0) and 1 for (1,1), with a single 1 in the other rows: OR.
- Output 0 for (0,0) and 0 for the mixed rows, 1 for (1,1): AND.
- Output 1 for (0,0) and 0 for (1,1), with 1 in the mixed rows: NAND.
- Output 1 for (0,0) and 0 elsewhere: NOR.
Common errors
- Treating NAND as "not both" but then writing 1 for input (1,1). The NAND output is 0 only when all inputs are 1.
- Confusing NOR with OR. NOR is 1 only when all inputs are 0.
- Forgetting that NOT has one input, so its table has two rows, not four.
Exercise
Inputs A = 1 and B = 0 are fed to a NOR gate. Its output goes into a NOT gate. What is the final output?
Show answer
The NOR gate gives NOT(1 + 0) = NOT(1) = 0. The NOT gate then inverts 0 to 1. The final output is 1, so the combination acts as an OR gate.