Ch 2. Internal Data Representation of Characters, Integers, Real Numbers
2.1 ASCII, EBCDIC and Unicode
In computing, characters such as letters, digits, punctuation marks, and control symbols must be represented in a format that computers can process. This is achieved through character encoding systems, which assign numeric codes to each character. The most widely used encoding systems include ASCII, EBCDIC, and Unicode.
ASCII (American Standard Code for Information Interchange) is one of the earliest and most widely adopted character encoding standards. In this system, each character is assigned a 7-bit integer, allowing 128 unique codes. These include uppercase and lowercase English letters, digits, punctuation marks and symbols, and control characters (e.g., newline, carriage return).
Example 2.1
The following table shows some ASCII characters, their decimal values, and binary values.
| ASCII | Decimal | Binary |
|---|---|---|
@ |
64 | 1000000 |
K |
75 | 1001011 |
7 |
55 | 0110111 |
m |
109 | 1101101 |
% |
37 | 0100101 |
R |
82 | 1010010 |
? |
63 | 0111111 |
2 |
50 | 0110010 |
h |
104 | 1101000 |
$ |
36 | 0100100 |
For example, the character ‘@‘ is represented by the decimal value 64, which is 1000000 in binary. The character ‘K’ is 75, and ‘7’ is 55.
ASCII is efficient and compact, making it ideal for early computing systems and still widely used in modern applications.
Example 2.2
To represent the word “Hi” in ASCII, the character ‘H’ has the ASCII decimal 72 and the ASCII binary (7-bit) 1001000. The character ‘i’ has the ASCII decimal 105 and the ASCII binary 1101011. So, the word “Hi” in ASCII binary is
1001000 1101001
This is how it would be stored in memory using ASCII encoding.
A less common character encoding system developed by IBM is EBCDIC (Extended Binary Coded Decimal Interchange Code). It is an 8-bit character encoding system used on mainframe and midrange systems. While it supports 256 characters, the layout differences make it incompatible with ASCII. For example, the character ‘@‘ is represented by the decimal value 124, the character ‘K’ is 210, and ‘7’ is 247. EBCDIC also supports characters such as ¢ and É that are not available in ASCII.
As computing became global, the need to represent characters from many languages and symbol sets led to the development of >Unicode, which supports over 150,000 characters. Unlike EBCDIC, Unicode is backwards compatible with ASCII, so characters like ‘A’ have decimal values of 65 in both systems. It also supports different encodings of Unicode Transformation Format (UTF) such as UTF-8 (1 to 4 bytes per character), UTF-16 (2 to 4 bytes per character), and UTF-32 (4 bytes per character). UTF-8 is widely used on the web.
Example 2.3
The characters “你” and “好” (Hello in Chinese) are encoded using UTF-8.
The character 你 has Unicode code point U+4F60, which has UTF-8 encoding (Hex) E4 BD A0 and UTF-8 Binary 11100100 10111101 10100000.
The character 好 has Unicode code point U+597D, UTF-8 Encoding E5 A5 BD and UTF-8 Binary 11100101 10100101 10111101.
When we combine these two binary numbers to make the word “你好”, we have the UTF-8 binary
11100100 10111101 10100000 11100101 10100101 10111101
This takes 6 bytes in UTF-8, compared to just 2 in ASCII for “Hi”.
Unicode enables consistent representation and handling of text across platforms, languages, and applications.
Real-World Example 2.1: Multilingual Messaging App
Suppose you have been assigned the task of developing a messaging app such as WhatsApp or WeChat that supports global users. Your app must handle messages in multiple languages, including English, Chinese, Arabic, and emojis, and correctly store, transmit, and display them.
>Consider the user input “Hello> 😊 你好”, which is a combination of ASCII (“Hello>”), Unicode emojis (😊) and Unicode Chinese characters (“你好”). Your app needs to use UTF-8 encoding to convert the input string to binary data. Each character is encoded into 1 to 4 bytes as follows:
- “H”, “e”, “l”, “o”, and “ “ (space) → 1 byte each
- “😊” → 4 bytes
- “
你” and “好” → 3 bytes each
The encoded binary data is sent over the Internet. Because UTF-8 is backward-compatible with ASCII, older systems can still interpret basic characters. The recipient’s device decodes the UTF-8 data back into characters. The message appears exactly as intended: “Hello 😊 你好”.
ASCII is fine for English-only systems. Unicode (especially UTF-8) is essential for global communication. Without proper encoding, messages could appear as garbled text (e.g., � or ???).