Course 10.2Lesson 2 of 3
The XOR gate gives 1 when its two inputs are different, and 0 when they are the same. You learn its symbol and truth table, how it differs from OR in exactly one row, and how it controls a light from two switches.
Try the code and the simulations beside the lesson.
A long staircase has a light switch at the bottom and another at the top. You switch the light on at the bottom and off at the top. Either switch changes the light, whatever the other one is doing. Which gate does that?
XOR stands for exclusive OR. The syllabus also calls it EOR. It gives 1 when the two inputs are different, and 0 when they are the same.
The symbol is the OR shape with a second curved line behind its back.
| A B | X = A XOR B | A OR B |
|---|---|---|
| 0 0 | 0 | 0 |
| 0 1 | 1 | 1 |
| 1 0 | 1 | 1 |
| 1 1 | 0 | 1 |
The logic expression is X = A XOR B.
Now the stair light. Let the bottom switch be A and the top switch be B. The light is X = A XOR B. Change either switch and the two inputs go from different to the same, or from the same to different. So the light always changes.
Look at the table again. XOR and OR agree in three rows. They differ only in the row 1 1. OR says "at least one", so it gives 1 there. XOR says "one or the other but not both", so it gives 0 there.
You can build XOR from AND, OR and NOT. It is 1 when A is 1 and B is not, or when B is 1 and A is not:
X = (A AND (NOT B)) OR ((NOT A) AND B)
Where two wires cross without a dot, they are not joined. A dot marks a point where one wire splits into two.
Check it in the row 0 1: A AND (NOT B) = 0 AND 0 = 0, and (NOT A) AND B = 1 AND 1 = 1. Then 0 OR 1 = 1. That matches XOR. A single XOR gate does the same job as these five gates.
The program writes XOR with !=, which means "is not equal to". It prints XOR next to OR, then flips a stair switch.
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
A = 1 and B = 1. What is the output?Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.