Course 1.2Lesson 1 of 3
A computer stores text by giving every character a number and storing that number in binary. You learn what a character set is, how ASCII and Unicode work, why Unicode can show far more characters, and how many bits a piece of text needs.
Try the code and the simulations beside the lesson.
When you press the key A, the computer does not store a picture of the letter. It stores a number. The keyboard sends a code, and the computer keeps that code in binary, just like any other number. Text is turned into binary so that the computer can process it.
A character is any single letter, digit, space, punctuation mark or symbol. A character set is the list of all the characters a computer can use, with the binary code of each one. The sender and the receiver must use the same character set, or the text comes out as nonsense.
ASCII stands for American standard code for information interchange. It is one of the oldest character sets.
The codes follow a pattern, so you can work many of them out.
| Character | Denary | Binary |
|---|---|---|
| A | 65 | 1000001 |
| B | 66 | 1000010 |
| a | 97 | 1100001 |
| 0 | 48 | 0110000 |
Notice that the character 5 (code 53) is not the number 5. A character code is only a label for a symbol.
ASCII has room for only 128 characters. That is enough for English, but not for the letters of other languages, mathematical symbols or emojis.
Unicode is a much larger character set. It allows a far greater range of characters and symbols than ASCII, including those of many different languages and emojis. To do this, Unicode needs more bits per character than ASCII. Common forms use 16 or 32 bits for each character. An examination question tells you how many bits each character uses.
The first 128 Unicode characters have the same codes as ASCII, so the letter A is 65 in both.
The number of bits a piece of text needs is easy to work out.
A message of 20 characters in 8-bit ASCII needs bits, which is 20 bytes. The same message in a 32-bit Unicode form needs bits. Every space and punctuation mark counts as a character.
Python's ord gives the code of a character and chr gives the character for a code. The program prints the codes of a word in denary and in 8-bit binary, then turns the word into small letters by adding 32.
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.