You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
The AND gate is one of the most important logic gates in computer science. It takes two inputs and produces an output of 1 only when both inputs are 1. This lesson covers the AND gate in detail as required by OCR J277 Section 2.5.
The AND gate implements logical conjunction. Think of it as requiring both conditions to be met. The output is 1 (true) only when input A and input B are both 1 (true). If either input is 0, the output is 0.
In Boolean algebra, AND is written as:
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Notice that the output is 1 in only one of the four rows — when both A and B are 1.
OCR Exam Tip: A quick way to remember the AND gate: the output is 1 only when all inputs are 1. In the truth table for two inputs, there is exactly one row with output 1 (the last row).
The standard AND gate symbol is a flat-backed D shape (a rectangle with a curved right side):
flowchart LR
A((A)) --> AND["AND gate"]
B((B)) --> AND
AND --> Q((Q))
The two inputs enter from the left, and the single output exits from the right. There is no bubble at the output (unlike NAND).
In Python:
# Using the and keyword
username = "admin"
password = "secret123"
if username == "admin" and password == "secret123":
print("Access granted")
else:
print("Access denied")
In OCR pseudocode:
username = "admin"
password = "secret123"
if username == "admin" AND password == "secret123" then
print("Access granted")
else
print("Access denied")
endif
Both the username and the password must be correct for access to be granted. If either one is wrong, access is denied. This is exactly how the AND gate behaves — both inputs must be 1 for the output to be 1.
Imagine two light switches connected in series (one after the other) controlling a single light bulb:
| Switch A | Switch B | Light |
|---|---|---|
| Off | Off | Off |
| Off | On | Off |
| On | Off | Off |
| On | On | On |
The light only turns on when both switches are on. This is an AND operation.
| Application | How AND is used |
|---|---|
| Security systems | A door unlocks only if the correct PIN is entered AND the correct fingerprint is scanned |
| Processor ALU | AND operations are used in bitwise calculations within the arithmetic logic unit |
| Subnet masking | In networking, an IP address is ANDed with a subnet mask to determine the network address |
| Conditional logic | Programs use AND to check multiple conditions are all true before proceeding |
When AND is applied to two binary numbers, each pair of corresponding bits is ANDed:
| Operation | Bit 1 | Bit 2 | Bit 3 | Bit 4 |
|---|---|---|---|---|
| 1 | 0 | 1 | 1 | |
| AND | 1 | 1 | 0 | 1 |
| Result | 1 | 0 | 0 | 1 |
Each column is processed independently:
OCR Exam Tip: Bitwise AND is used in subnet masking (covered in the networking section of J277). Understanding how AND works bit by bit will help you answer networking questions too.
Confusing AND with OR — AND requires both inputs to be 1; OR requires at least one. The AND truth table has only one row with output 1; the OR truth table has three.
Writing the wrong symbol — the AND symbol has a flat left side and curved right side. Do not add a bubble (that would make it NAND).
Forgetting that 0 AND anything = 0 — if either input is 0, the output is always 0.
Example 1: Evaluate A . B for specific inputs.
Let A = 1 and B = 0. Then A . B = 1 . 0 = 0. The AND gate requires both to be 1, so a single 0 drags the output down to 0.
Example 2: AND with three inputs.
Evaluate Q = A . B . C when A = 1, B = 1, C = 1.
Q = 1 . 1 . 1 = 1. Only this single combination gives Q = 1 out of eight possibilities.
Example 3: AND inside a combined expression.
Evaluate Q = (A . B) + C when A = 1, B = 0, C = 1.
Step 1: A . B = 1 . 0 = 0. Step 2: Q = 0 + 1 = 1.
An AND gate is not limited to two inputs. A 3-input AND outputs 1 only when all three inputs are 1:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.