☰ خطة العام · تكنولوجيا المعلومات والاتصالات (بالإنجليزية)

Gates in decisions: NAND, NOR and XOR

الأسبوع 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.

AB¬(A∧B)¬(A∨B)A⊕B
00110
01101
10101
11000
Worked examples
Php
1for ($a = 0; $a <= 1; $a++) {
2    for ($b = 0; $b <= 1; $b++) {
3        echo $a, " ", $b, "   ", (int)!($a && $b), " ", (int)!($a || $b), " ", $a ^ $b, "\n";
4    }
5}
Output
0 0   1 1 0
0 1   1 0 1
1 0   1 0 1
1 1   0 0 0
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
Output
False False   True True False
False True   True False True
True False   True False True
True True   False False False
The same three columns in VB.NET, inside a small console program. Boolean values print as True and False.
ABA∨B¬(A∧B)(A∨B)∧¬(A∧B)
00010
01111
10111
11100
XOR built from the basic gates: (A OR B) AND NOT (A AND B). The last column equals XOR.
RuleGate
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?
2
For which row of two inputs does NOR give 1?
3
How many rows of a two-input XOR have the output 1?
4
What does 6 ^ 3 give in PHP?