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):
A ----+ +---- Q
| AND |
B ----+ +
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.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.