2.7 - Characters
Binary representation of characters
Computers process all data in binary form, which consists of bits (binary digits) that are either 0 or 1. This includes not just numbers, but also text, images, and sounds. For text, words are built from individual characters, which must be converted into binary for the computer to handle them.
Characters are symbols used in writing, such as letters, digits, and punctuation. Alphanumeric characters specifically include uppercase and lowercase letters (A-Z, a-z), digits (0-9), and symbols like ?, +, and £. Since computers cannot directly understand these human-readable symbols, they use a system to map each character to a unique binary code.
This mapping allows the computer to store, process, and display text accurately. When you press a key on a keyboard, it sends a binary signal to the computer, which then translates that signal into the corresponding character for display or storage.
The role of character sets
A character set is a collection of characters that a computer can recognise and represent using binary codes. Each character in the set is assigned a unique binary value, enabling the conversion between human-readable text and machine-readable binary.
Key features of character sets:
- Character inclusion - They contain alphanumeric characters, symbols, and special characters that trigger commands, such as enter (for new lines) or delete (for removing text).
- Binary conversion - Character sets provide the rules for translating binary codes back into characters, and vice versa.
- Distinction from fonts - A character set defines what the character is (e.g., the letter 'A'), while a font determines how it appears visually (e.g., bold or italic style).
The number of bits required for each character depends on the size of the character set. Larger sets need more bits to provide unique codes for more characters. For example, a set with 128 characters requires at least 7 bits (since 27 = 128).
ASCII character set
ASCII (American Standard Code for Information Interchange) is a widely used character set, especially in English-speaking regions. It assigns a 7-bit binary code to each character, allowing for 128 unique representations (27 = 128). This covers all English letters, digits, symbols, and basic commands.
Structure and features of ASCII:
- Extended to 8 bits - An extra 0 bit is often added at the start, making each code 8 bits (1 byte) for easier storage and processing.
- Ordered codes - Codes for digits, uppercase letters, and lowercase letters are sequential (e.g., 'A' before 'B'). Symbols and commands are placed throughout.
- Common uses - ASCII is simple and efficient for basic text in English, but limited for other languages.
Examples of ASCII characters:
| Character | Binary | Hex | Decimal |
|---|---|---|---|
| Backspace | 0000 1000 | 08 | 8 |
| 0 | 0011 0000 | 30 | 48 |
| 1 | 0011 0001 | 31 | 49 |
| = | 0011 1101 | 3D | 61 |
| A | 0100 0001 | 41 | 65 |
| B | 0100 0010 | 42 | 66 |
| ] | 0101 1101 | 5D | 93 |
| a | 0110 0001 | 61 | 97 |
| b | 0110 0010 | 62 | 98 |
Unicode character set
Unicode is a more comprehensive character set designed to represent characters from all major languages worldwide. Unlike ASCII, it uses multiple bytes per character, allowing for thousands of unique codes.
Advantages and features of Unicode:
- Global coverage - It includes characters from diverse alphabets, such as Greek, Russian, Chinese, and many others, making it suitable for international use.
- Compatibility with ASCII - The first 128 codes in Unicode match ASCII exactly, ensuring backward compatibility.
- Flexibility - Different forms of Unicode (e.g., UTF-8, UTF-16) vary in byte usage, balancing efficiency and range.
Unicode's expanded capacity addresses ASCII's limitations, enabling computers to handle multilingual text without issues.
Calculating text file sizes
Text files store characters using the codes from a character set. The size of a text file depends on the number of characters and the bits per character.
Formula for text file size:
Where:
- Number of bits per character = The bit length used by the character set (e.g., 8 for ASCII)
- Number of characters = The total count of symbols in the file
Worked example - Calculating text file size
A text file uses the ASCII character set (8 bits per character) and contains 250 characters. Calculate the file size in bits.
Step 1: Identify the values
- Bits per character = 8
- Number of characters = 250
Step 2: Apply the formula