Numbers and Codes
Text as numbers
Work out the code number a character is stored as, and how many bytes a piece of text needs.
A computer's memory holds nothing but numbers, so a letter has to be turned into one before it can be stored at all. The way that is done is deliberately dull: everybody agrees on a table that gives every character its own number, and then a letter is simply that number. The agreement is the whole of it — there is nothing about the letter itself that makes it one number rather than another, and if two machines disagreed about the table they would read each other's writing as gibberish. The tables in use put the characters in the order you would expect, which is the one useful thing about them: once you know where a run of characters starts, you can work out any character in that run by counting.
A character is not a value
The character 5 and the number 5 are two different things stored two different ways, and mixing them up is the classic mistake here. A number is stored as the amount it is worth; a character is stored as whatever the code table says, which has nothing to do with the amount. That is also why a capital letter and its small letter are two separate characters with two separate code numbers — the machine has no idea they are the same letter, though the gap between the two is the same for every letter of the alphabet.
Worked example
Capital A is stored as 65. What is stored for capital K?
Count along the alphabet from A to K. A, B, C, D, E, F, G, H, I, J, K — that is ten letters after A.
Counting the steps rather than the letters is what stops the usual slip. K is the eleventh letter, but it is only ten steps away from A.
Try it together
Now work out how the word CUP is stored, one character per byte, with the capitals running in order from 65.
Take the characters one at a time, then think about the message as a whole.
1.What number is stored for capital C?
Have a go
Have a go on your own. Small letters run in order from 97. What number is stored for small j?
Ready to practice?
Eight questions on what you have just read. Nothing is timed, and you can play as many times as you like.