The converter as a PHP web page
Answers are for parents and teachers.
1
The visitor types 2C and presses the hexadecimal button on the page of this week. What are the three results? Show the working.
Decimal 44, because 2 × 16 + 12 = 44; binary 101100; hexadecimal shown as typed, 2C.
2
The visitor types 59 and presses the decimal button. What are the binary and hexadecimal results?
Binary 111011 and hexadecimal 3b (59 = 3 × 16 + 11).
3
Write the PHP test that is true only when a button named btnShow was pressed.
isset($_POST['btnShow'])
4
A pupil writes $dec = bindec($_POST['number']); outside every isset test. Why is this a poor place for it?
It runs on every visit, including the first one, when nothing has been sent yet, so there is no typed number to convert.
5
Which of these does the checked converter accept for the decimal button: 4096, 40 96, -12, 12345678901? Give the reason for each one that is refused.
It accepts 4096. It refuses 40 96 (a space), -12 (a minus sign) and 12345678901 (more than nine digits).