Week 15 · Term 1 review (Units 1–2) and your own mini-project · 3 lessons
2
Review: gates, truth tables and simulators
ICT Secondary 3 Term 1, Review: pp. 5–86
GoalReview the gates, the truth tables, the simulators and the operators of PHP and VB.NET with new mixed tasks.
New words
row count · 2ⁿ rows for a gate with n inputsoperator · a sign or word that works on values, such as &&, || or Nottrace · to follow code or clicks and write down the state after each stepfault finding · reading code to find the line that breaks the rule
Explanation
Unit 2 in one page. A gate has inputs and exactly one output; with n inputs its truth table has 2ⁿ rows. AND is 1 only when all inputs are 1; OR is 1 when at least one is 1; NOT reverses its one input; NAND, NOR and XOR are NOT AND, NOT OR and “exactly one”. The simulators keep a state, the texts of the switches and the lamp, and change it in click code. The inner If is the difference: in AND it checks the other switch when a switch is turned On, in OR when a switch is turned Off, and NOT needs none. On a web page the same rules are written with &&, || and !, after isset says that Apply was pressed, and the page accepts only the values on and off. Remember the traps. In OR, the plus sign is not ordinary addition, and 1 + 1 gives 1. In PHP, = stores and == compares, | works on bits while || joins conditions, and echo !1 prints nothing. In VB.NET, Not 1 on a whole number is −2. To find a fault, read the code, predict the output, and compare it with the rule.
Predict the output before you read the answer. With a = 1 and b = 0 the line prints AND, OR, NOT a and XOR in this order.
Step
Click
A
B
Lamp
0
(start)
Off
Off
unlit
1
B
Off
On
unlit
2
A
On
On
lit
3
B
On
Off
unlit
Which simulator made this trace? Compare the lamp with the texts: it is lit only at step 2, where both texts are On, so this is the AND simulator.
Php
1echo "NOT 1 is [", !1, "]";
Output
NOT 1 is []
Fault finding. A pupil wants to print NOT of the bit 1 and writes this PHP line and this VB.NET code. Neither prints 0. The fixes are (int)!1 in PHP, which prints 0, and 1 − bit in VB.NET, which gives 0.
Vb
1Dim bit As Integer = 12Console.WriteLine("NOT 1 is " & Not bit)
Output
NOT 1 is -2
The VB.NET version of the same fault.
Gate
Inputs
Rows
Rows with the output 1
AND
6
64
1
OR
6
64
63
NOR
4
16
1
NOT
1
2
1
How many rows, and how many rows with the output 1, for gates with more inputs.
Class activity
Write four tasks about gates for a classmate: a rule for which the classmate must choose the gate, a truth table with one missing column, a trace of clicks, and a code line whose output must be predicted. Write the answers on a separate line.
Practice
1
How many rows of a five-input NOR gate have the output 1?
One: the row of five 0s.
2
In which simulator can one click, from the start state with both switches Off, light the lamp?
In the OR simulator.
3
What does 6 & 3 give in PHP?
2, because 110 AND 011 gives 010.
4
Which two PHP operators mean AND and OR for conditions?