Course 10.1Lesson 1 of 3
A logic gate takes inputs that are 0 or 1 and gives one output that is 0 or 1. This lesson shows the six gate symbols you must draw in the examination, explains a truth table, and starts with the simplest gate, NOT, which gives the opposite of its one input.
This lesson is free to read. Enroll free to keep your place and take the tests.
Try the code and the simulations beside the lesson.
Think of a light switch. It is either on or off. There is no half way. A door is open or shut. A button is pressed or not pressed.
A computer works with values like these. It stores and handles everything as binary, as 0 and 1. Inside the processor, the 0s and 1s are handled by tiny electronic parts called logic gates.
We read 1 as on or true, and 0 as off or false. This kind of logic, with only two values, is called Boolean logic.
The syllabus names six gates: NOT, AND, OR, NAND, NOR and XOR. XOR is also written EOR. In the examination you draw circuits with these exact symbols, so learn their shapes now.
Look at the shapes.
NOT is the only gate with one input. Every other gate in this syllabus has exactly two inputs. The small circle always means "then take the opposite". You will meet it again in the next course.
How do we show what a gate does? We list every possible input and the output for each one. This list is a truth table.
A gate with one input has two rows, because the input can be 0 or 1. A gate with two inputs has four rows. With three inputs there are eight rows.
The NOT gate gives the opposite of its input. A 1 goes in and a 0 comes out. A 0 goes in and a 1 comes out.
| A | X = NOT A |
|---|---|
| 0 | 1 |
| 1 | 0 |
We write this as the logic expression X = NOT A. Read it as "X equals not A".
An example. A night light has a light sensor. The sensor gives 1 when it is light outside. We want the lamp on when it is not light. So the lamp is X = NOT L, where L is the sensor. In the day, L = 1 and the lamp is off. At night, L = 0 and the lamp is on.
The program writes the NOT gate as a small function. It prints both rows of the truth table, then works out the night light. Here 1 - a turns 1 into 0 and 0 into 1.
You met not in Python in the course And, Or, Not: Combining Conditions of the Python Foundations book. A logic gate does the same job with 0 and 1 instead of True and False.
X = NOT A.Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
C gives 1 when the room is cold. Write the logic expression for the fan F.Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…