Computer Science · Ch 2 — Encoding Schemes and Number System
American Standard Code for Information Interchange (ASCII)
American Standard Code for Information Interchange (ASCII)
In the early 1960s, computers could not communicate with one another: each machine represented the keys of its keyboard in its own way, so text produced on one computer meant nothing to another. The need for a common standard was recognised, and the encoding scheme ASCII — American Standard Code for Information Interchange — was developed to standardise how characters are represented. ASCII remains the most commonly used coding scheme even today.
Why 7-bit ASCII can encode exactly 128 characters
Initially, ASCII used 7 bits to represent each character. Since a binary digit can take only 2 values (0 or 1), a string of 7 bits can form:
2^7 = 128 distinct patterns
So 7-bit ASCII can encode 128 different characters — enough for every key on an English keyboard: uppercase and lowercase letters, digits, punctuation marks and control characters.
Limitation: ASCII can encode the character set of the English language only. Other scripts (such as Indian languages) have no place in the 128 codes — this is precisely the gap that ISCII and UNICODE (next sections) were created to fill.
A sample of printable ASCII codes
Some printable characters and their decimal code values (from the ASCII table):
| Character | Decimal | Character | Decimal | Character | Decimal |
|---|---|---|---|---|---|
| Space | 32 | @ | 64 | ` (backtick) | 96 |
| ! | 33 | A | 65 | a | 97 |
| " | 34 | B | 66 | b | 98 |
| # | 35 | C | 67 | c | 99 |
| dollar sign | 36 | D | 68 | d | 100 |
| % | 37 | E | 69 | e | 101 |
| & | 38 | F | 70 | f | 102 |
| ' | 39 | G | 71 | g | 103 |
| ( | 40 | H | 72 | h | 104 |
| ) | 41 | I | 73 | i | 105 |
Notice the pattern: uppercase letters start at 65 (A) and run consecutively; lowercase letters start at 97 (a). Uppercase and lowercase versions of the same letter have different codes — the computer treats 'A' (65) and 'a' (97) as different characters.
Worked example — encoding a whole word (Example 2.2)
Task: encode the word DATA and convert the encoded values into binary, the form a computer understands.
Look up each letter's ASCII value, then write each value as a 7-bit binary code:
- D → ASCII 68 → 7-bit binary 1000100
- A → ASCII 65 → 7-bit binary 1000001
- T → ASCII 84 → 7-bit binary 1010100
- A → ASCII 65 → 7-bit binary 1000001
Replacing every letter with its code gives the word's ASCII form and its binary form:
| D | A | T | A | |
|---|---|---|---|---|
| ASCII code | 68 | 65 | 84 | 65 |
| Binary code | 1000100 | 1000001 | 1010100 | 1000001 |
So the text "DATA" travels through the computer as the bit stream 1000100 1000001 1010100 1000001.
You can verify these codes yourself in Python:
for ch in "DATA": …
| Character | Decimal Value | Character | Decimal Value | Character | Decimal Value |
|---|---|---|---|---|---|
| Space | 32 | @ | 64 | ` | 96 |
| ! | 33 | A | 65 | a | 97 |
| “ | 34 | B | 66 | b | 98 |
| # | 35 | C | 67 | c | 99 |
| D | A | T | A | |
|---|---|---|---|---|
| ASCII Code | 68 | 65 | 84 | 65 |