ASCII
ASCII is one specific text encoding scheme.
It was one of the first text encoding schemes that came about.
How many bits?
ASCII can store 128 different characters. That means we need to use 7 bits to
store each character, because
ASCII character codes
The ASCII character code for ‘A’ is 65, and the ASCII character code for ‘a’ is 97. If we include numbers, the character ‘0’ has the ASCII character code 48.
From that, you can work out all the other letters, because they are sequential!
The code for ‘B’ is 66, ‘C’ is 67, and so on. The code for ‘b’ is 98, ‘c’ is 99, and again, so on. That’s one of the reasons ASCII is nice to work with!
Benefits of ASCII
- It’s simple and easy to understand.
- It’s very widely supported and used almost everywhere
- It can represent all the basic English letters, numbers and symbols.
- It only takes up 7 bits per character (minimum, it can be stored in 8 bits or more depending on the implementation)
- If you look at any successive 7 bits, you know exactly which character it
represents. With UTF-8, for example, not all characters are represented by
the same number of bits.
- This is an important one. Think of when you want to ‘substring’ a string when programming: with ASCII strings, we know exactly where the nth character is, just by adding an offset to the start of the string.
- With UTF-8, we can’t do that, because we don’t know how many bits each character is represented by. So we have to read through the string from the start to find the nth character.
Drawbacks of ASCII
- It can only represent 128 characters, which is not enough for many languages and symbols.
- Even extended-ASCII which uses 8 bits can only represent 256 characters, which is still not enough for many languages and symbols.
- It wasn’t really built for non-English languages
- We’re stuck with the characters we’ve got - there’s no way to add more characters to ASCII, like we can do with unicode!
flashcards
| Question | Answer |
|---|---|
| What is the name of the specific text encoding scheme described? | ASCII |
| How many different characters can ASCII store? | 128 |
| How many bits are needed to store each ASCII character? | 7 bits, because |
| What is the ASCII code for the character ‘A’? | 65 |
| What is the ASCII code for the character ‘a’? | 97 |
| What is the ASCII code for the character ‘0’ (zero)? | 48 |
| If ‘B’ has ASCII code 66 and ‘A’ has code 65, how are the letter codes arranged? | They are sequential. |
| What is a benefit of ASCII regarding extracting a substring? | With ASCII, you know exactly where the nth character is by adding an offset to the start of the string. |
| Why can’t you find the nth character of a UTF-8 string by simply adding an offset? | Because in UTF-8, not all characters are represented by the same number of bits (unlike ASCII). |
| What is a major drawback of ASCII concerning languages? | It can only represent 128 (or 256 with extended-ASCII) characters, which is not enough for many languages and symbols. |
| Why can’t we add more characters to ASCII? | ASCII doesn’t support adding more characters like Unicode does. |