Computers are sophisticated calculators, and deal exclusively with numbers (digits). In order to get them to cope with other types of information, we have to encode that information in a numerical (digital) way. Let’s say that we give every letter of the alphabet a unique number, for example:
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| A | B | C | D | E | F | G | H | I | J | K | L | M |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
While we’re at it, we should give all the symbols we would possibly want to use a number:
| 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
|---|---|---|---|---|---|---|---|---|---|
| ! | " | £ | $ | % | ^ | & | * | ( | ) |
And if we want to represent numbers themselves as text rather than their numerical value, we should give each of the numbers a number:
| 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Letters, symbols, and numbers collectively are known as characters. A set deciding which character gets which number is known as a character encoding. Clearly, if we want to copy and paste text from one program to another, or just send an email, everyone needs to agree on which character encoding to use. Two of the most popular character encodings are known as ASCII and Unicode.
Characters on their own are not as much use as lists of characters. When we put characters together side by side we can make words, sentences, or entire books.
| 8 | 5 | 12 | 12 | 15 | 27 |
|---|---|---|---|---|---|
| H | E | L | L | O | ! |
A list of characters is known as a string. To tell the compiler we want to specify a string, we use a pair of " symbols. Everything between the " symbols will be encoded by the compiler as a list of characters, for example:
"Hello"
The string must all be on one line however, and we can’t use the " character inside a string or the compiler will get confused about where the string ends, and the rest of the program begins.
Compile and run the program to see what happens
Replace the characters inside the “ symbols with your own name, and compile and run again.