Exam-style question
Try this first
A program receives the text '42'. Explain why it should be treated as two character codes if the input is text, and contrast this with storing the numerical value 42 in pure binary.
Model answer
What a good answer should say
- The text '42' contains two characters: '4' followed by '2'.
- Each character is represented by its own character code, so the program receives two coded characters.
- In contrast, the numerical value 42 is stored as one number in pure binary.
- The two forms may contain different bit patterns and must not be confused when performing numerical operations.
Explanation
Why this works
The number of characters and the numerical value are separate ideas. Text input preserves the individual digit characters, whereas a numerical value represents the quantity 42.
A program may need to convert between these forms before carrying out arithmetic.
Common mistake
No common mistake is linked to this question yet.
