Lesson 42: Logic gates
Trang này cần trình duyệt gần đây (hỗ trợ SharedArrayBuffer). Vui lòng cập nhật Chrome, Edge, Firefox hoặc Safari lên phiên bản mới nhất.
English
Gates you can press
- A logic gate takes inputs that are 1 or 0 and gives one output.
- Here the inputs are two buttons: pressed is 1, not pressed is 0. Each LED is the output of one gate.
- Press the buttons on the board and fill in the truth tables yourself.
Words for this lesson
| Word | Meaning |
|---|---|
| AND | 1 only if both inputs are 1 |
| OR | 1 if at least one input is 1 |
| NOT | the opposite of the input |
| NAND / NOR | NOT AND / NOT OR |
| XOR | 1 if the inputs are different |
English
Truth tables
| A | B | AND | OR | XOR |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 |
- NAND is the opposite of AND: 1, 1, 1, 0. NOR is the opposite of OR: 1, 0, 0, 0.
English
Gates in C++
| Gate | C++ |
|---|---|
| A AND B | A && B |
| A OR B | A || B |
| NOT A | !A |
| A NAND B | !(A && B) |
| A XOR B | A != B |
English
In the exam
- 0478/22/M/J/25 Q8(a): draw the XOR symbol and complete its truth table: 0, 1, 1, 0, the same as your XOR LED.
- 0478/12/F/M/22 Q3(a): tick the gates that give 1. A = 1, B = 1: AND and OR. A = 0, B = 0: NAND and NOR. A = 1, B = 0: OR, NAND and XOR. Press the buttons to check each row.
Độ khó 3/5 · 200 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Button A is on pin 2 and button B on pin 3 (pressed reads LOW, so A is true while A is pressed). Make the three LEDs into logic gates: pin 11 shows A AND B, pin 12 shows A OR B, and pin 13 shows NOT A. Check presses no button, then A, then B, then both.
Nhấn Chạy để xem kết quả ở đây.
Độ khó 4/5 · 280 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Now three more gates: pin 11 shows A NAND B (NOT (A AND B)), pin 12 shows A NOR B (NOT (A OR B)), and pin 13 shows A XOR B: on when exactly one button is pressed, not both.
Nhấn Chạy để xem kết quả ở đây.