الأسبوع 14 · الوحدة ٢ الموضوع العاشر: توظيف البوابات المنطقية في اتخاذ القرارات الحياتية، خاتمة الكتاب، وبوابات NAND وNOR وXOR المذكورة في مقدمة الوحدة · 3 دروس
3
Beyond the basics: NAND, NOR and XOR
ICT Secondary 3 Term 1, Unit 2, Topic 10: pp. 82–86
GoalDefine NAND, NOR and XOR from AND, OR and NOT, and read their truth tables.
New words
NAND · NOT AND: the output is 0 only when all the inputs are 1NOR · NOT OR: the output is 1 only when all the inputs are 0XOR · exclusive OR: the output is 1 when the inputs are differentXNOR · NOT XOR: named in the book but not studied here
Explanation
The book names three more gates and draws their symbols, without a table. We can build them from the three we know. NAND is AND followed by NOT: take the AND column and reverse it. For the rows 00, 01, 10, 11 it gives 1, 1, 1, 0, so it is 0 only for the row 11. NOR is OR followed by NOT: it gives 1, 0, 0, 0, so it is 1 only for the row 00. XOR is “exclusive OR”. It is like OR, except that it is 0 when both inputs are 1: it is 1 exactly when the two inputs are different, which gives 0, 1, 1, 0. Remember “tea or coffee” in Week 11: that everyday “or” is an XOR. In their symbols, NAND and NOR are the AND and OR shapes with the small reversing circle of the NOT gate, and XOR is the OR shape with an extra curved line. XNOR is NOT XOR, 1 when the inputs are equal; it is only named here. In PHP the three columns are (int)!($a && $b), (int)!($a || $b) and $a ^ $b. In VB.NET they are Not (a And b), Not (a Or b) and a Xor b.
The three columns printed by PHP. The output lines come from running it.
Vb
1For Each a As Boolean In {False, True}
2 For Each b As Boolean In {False, True}
3 Console.WriteLine(a & " " & b & " " & (Not (a And b)) & " " & (Not (a Or b)) & " " & (a Xor b))
4 Next
5Next
The same three columns in VB.NET, inside a small console program. Boolean values print as True and False.
A
B
A∨B
¬(A∧B)
(A∨B)∧¬(A∧B)
0
0
0
1
0
0
1
1
1
1
1
0
1
1
1
1
1
1
0
0
XOR built from the basic gates: (A OR B) AND NOT (A AND B). The last column equals XOR.
Rule
Gate
The stair lamp is lit when the two wall switches are in different positions.
XOR
The warning light is lit unless both locks are closed.
NAND
The “Quiet” sign is lit when neither the radio nor the TV is on.
NOR
Three invented rules and their gates.
Class activity
Fill in a table with the columns A, B, A OR B, A AND B, NOT (A AND B) and (A OR B) AND NOT (A AND B). Check that the last column is XOR, and say which everyday rule it describes.
Practice
1
For which row of two inputs does NAND give 0?
For the row 11.
2
For which row of two inputs does NOR give 1?
For the row 00.
3
How many rows of a two-input XOR have the output 1?