Course 10.1Lesson 2 of 3
An AND gate gives 1 only when both of its inputs are 1. You learn its symbol, its truth table with the rows in the order the examination uses, and the logic expression A AND B. Then you use it for everyday rules with the word and.
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.
A hand dryer runs when your hands are under it and the power is on. Either one alone is not enough. A machine in a workshop starts when the safety guard is closed and the start button is pressed. These rules need both conditions at the same time.
The AND gate gives 1 only when input A and input B are both 1. In every other case it gives 0.
The symbol has a flat back and a round front. The two inputs come in on the left, and the output leaves on the right.
| A B | X = A AND B |
|---|---|
| 0 0 | 0 |
| 0 1 | 0 |
| 1 0 | 0 |
| 1 1 | 1 |
The logic expression is X = A AND B.
The examination always lists the rows in the same order. Read the inputs as a binary number and count up: 0 0, then 0 1, then 1 0, then 1 1. The input A changes slowest and B changes fastest. Use this order every time. Then you can never miss a row or write one twice.
An example. A safe opens when the key is turned (K = 1) and the right code is typed (C = 1). The rule is S = K AND C. Check the four rows. Only K = 1, C = 1 opens the safe. If either is 0, the safe stays shut.
The word "and" in a problem is a strong sign that you need an AND gate. Read the sentence carefully though. "The light is on when the door is open and it is dark" has one AND, between "the door is open" and "it is dark".
The program writes the AND gate as a function. The two loops print the rows in the examination order. Then it works out the hand dryer.
In Python, the word and does the same job for True and False. In Cambridge pseudocode the same word AND joins two conditions. You will see this in the last lesson of this chapter.
X = A AND B.Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
A = 1 and B = 0. What is the output?W = 1) and the switch is pressed (P = 1). Write the expression for the kettle K.Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…