Sub topic 13
OR, AND, and NOT Gates with Truth Tables
This chapter assumes you know what a binary signal is (logic 0 and logic 1, from the previous chapter), and that you can read a simple table. No circuit analysis is needed. You will learn the three basic gates, how to write their truth tables, how to combine them, and which mistakes cost marks in NEET.
What a logic gate is
A logic gate is a circuit with one or more binary inputs and one binary output. The output depends only on the present inputs, and it follows a fixed rule. In NEET, you treat a gate as a black box and work with its rule.
A truth table lists every possible input combination and the output for each. A gate with n inputs has 2^n rows. One input gives 2 rows. Two inputs give 4 rows. Three inputs give 8 rows.
| Gate | Inputs | Rows in truth table |
|---|---|---|
| NOT | 1 | 2 |
| OR, AND | 2 | 4 |
| OR, AND | 3 | 8 |
The OR gate
The OR gate outputs 1 if at least one input is 1. It outputs 0 only when all inputs are 0.
The Boolean expression is Y = A + B. Here "+" means logical OR. It is not arithmetic addition, although it looks like it. This is why 1 + 1 = 1 in Boolean algebra.
| A | B | Y = A + B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
A useful memory aid: two switches in parallel feeding a lamp. The lamp lights if either switch is closed.
The AND gate
The AND gate outputs 1 only when all inputs are 1. Any 0 input forces the output to 0.
The Boolean expression is Y = A · B (also written AB). The dot means logical AND, so it behaves like ordinary multiplication on 0 and 1.
| A | B | Y = A · B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
The memory aid here is two switches in series. The lamp lights only if both are closed.
The NOT gate
The NOT gate, also called an inverter, has one input and one output. The output is the opposite of the input.
The Boolean expression is Y = A̅ (A with a bar). Some books write Y = A'.
| A | Y = NOT A |
|---|---|
| 0 | 1 |
| 1 | 0 |
Applying NOT twice returns the original value: the double complement of A is A. This fact is used constantly when simplifying circuits.
Comparing the three gates
| Gate | Output is 1 when | Output is 0 when | Number of 1s in a 2-input table |
|---|---|---|---|
| OR | any input is 1 | all inputs are 0 | 3 |
| AND | all inputs are 1 | any input is 0 | 1 |
| NOT | input is 0 | input is 1 | 1 of 2 rows |
Notice the symmetry. OR is "mostly 1", with a single 0 row. AND is "mostly 0", with a single 1 row. Recognizing these patterns lets you identify a gate from an incomplete table.
Generating the tables with code
You can check any table by evaluating the gate on every input combination. The Python snippet below uses bitwise operators, which work on the integers 0 and 1. It prints the four two-input gates, including NAND and NOR, which you will study later in this tutorial.
from itertools import product
gates = {
"AND": lambda a, b: a & b,
"OR": lambda a, b: a | b,
"NAND": lambda a, b: 1 - (a & b),
"NOR": lambda a, b: 1 - (a | b),
}
for name, gate in gates.items():
print(name)
for a, b in product((0, 1), repeat=2):
print(a, b, "->", gate(a, b))The call product((0, 1), repeat=2) produces (0,0), (0,1), (1,0), (1,1). That is the standard input order in a truth table, which counts up in binary.
Gate symbols and the relationship to switches
The following diagram shows the two switch models. OR corresponds to parallel paths. AND corresponds to a series path.
Combining gates
Real questions chain gates together. The method is always the same: label the output of each gate, then compute step by step.
Consider Y = (A + B) · C̅. This uses an OR gate on A and B, a NOT gate on C, and an AND gate combining the two results.
Let P = A + B and Q = C̅. Then Y = P · Q.
| A | B | C | P = A + B | Q = C̅ | Y = P · Q |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 | 1 |
| 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 |
The output is 1 exactly when C = 0 and at least one of A, B is 1.
You can automate this with a small function. The program below also builds the table of a three-input expression.
from itertools import product
def NOT(a):
return 1 - a
def AND(a, b):
return a & b
def OR(a, b):
return a | b
print("A B C | Y")
for a, b, c in product((0, 1), repeat=3):
y = AND(OR(a, b), NOT(c))
print(a, b, c, "|", y)Handling time-varying inputs
NEET often gives input waveforms for A and B and asks for the output waveform. Treat each time interval as one row of the truth table.
Suppose A is 0, 1, 1, 0 and B is 1, 1, 0, 0 over four equal intervals.
| Interval | A | B | OR output | AND output |
|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 |
| 2 | 1 | 1 | 1 | 1 |
| 3 | 1 | 0 | 1 | 0 |
| 4 | 0 | 0 | 0 | 0 |
The OR output is 1, 1, 1, 0. The AND output is 0, 1, 0, 0.
Useful identities
These follow directly from the truth tables. Each helps you simplify an expression before drawing or evaluating it.
| Identity | Meaning |
|---|---|
| A + 0 = A | OR with 0 changes nothing |
| A + 1 = 1 | OR with 1 forces 1 |
| A · 0 = 0 | AND with 0 forces 0 |
| A · 1 = A | AND with 1 changes nothing |
| A + A = A | repeated input in OR |
| A · A = A | repeated input in AND |
| A + A̅ = 1 | a value or its opposite is always 1 |
| A · A̅ = 0 | a value and its opposite is never 1 |
If both inputs of an OR or AND gate are tied together, the gate acts as a buffer: Y = A. If you see this in a problem, replace the gate with a plain wire.
Common errors
- Mixing up OR and AND on the "1 + 1" row. Both give 1 there, so that row cannot tell you which gate it is. Check the 0,1 row: OR gives 1, AND gives 0.
- Applying the NOT bar to the wrong part. A̅ · B means (NOT A) AND B. A bar drawn over the whole product AB is a different expression, which belongs to the NAND gate.
- Skipping intermediate columns in multi-gate problems. Write a column for each gate output. Errors usually appear when you try to do two gates in your head.
- Listing rows out of order or missing rows. Always count up in binary so that all 2^n rows appear exactly once.
- Treating the gate as having memory. These gates are combinational, so the output follows the present inputs only.
Exercises
Exercise
A two-input gate gives output 0 for inputs (0,0), (0,1) and (1,0), and output 1 for (1,1). Which gate is it? What is the output if both inputs are joined to a single signal X?
Show answer
It is an AND gate, because the only 1 appears when both inputs are 1. If both inputs are joined to X, Y = X · X = X, so the gate behaves as a buffer and the output equals X.
Exercise
For Y = A̅ + B, complete the output for all four combinations of A and B in the order (0,0), (0,1), (1,0), (1,1).
Show answer
A̅ is 1, 1, 0, 0. OR-ing with B (0, 1, 0, 1) gives Y = 1, 1, 0, 1. The output is 0 only when A = 1 and B = 0.
Exercise
Inputs A = 1, 0, 1, 0 and B = 1, 1, 0, 0 are applied in four successive intervals to an AND gate whose output feeds a NOT gate. What is the final output sequence?
Show answer
The AND output is 1, 0, 0, 0. The NOT gate inverts it, so the final output is 0, 1, 1, 1.