📚 Data Representation: Number Systems, Text, Images and Compression | 数据表示:数制、文本、图像与压缩
Data representation is the foundation of all computer science. Computers store and process everything using binary, but understanding how numbers, text, and images are encoded is crucial for mastering CIE Computer Science. This guide breaks down the essential concepts, formulas, and exam techniques.
数据表示是所有计算机科学的基础。计算机使用二进制来存储和处理一切信息,但理解数字、文本和图像如何被编码,对于掌握 CIE 计算机科学至关重要。本指南将详细解析核心概念、公式和考试技巧。
1. Number Systems: Denary, Binary, and Hexadecimal | 数制:十进制、二进制与十六进制
Computers use the binary system (base-2) because transistors have two stable states, representing 0 and 1. Humans typically use the denary system (base-10). Hexadecimal (base-16) acts as a convenient shorthand for binary, making it easier for programmers to read and write low-level data.
计算机使用二进制(基数为 2),因为晶体管具有两种稳定状态,分别代表 0 和 1。人类通常使用十进制(基数为 10)。十六进制(基数为 16)是二进制的便捷简写形式,使程序员更容易阅读和编写底层数据。
- Denary (Base 10): Digits are 0-9. Each place value is a power of 10.
- 二进制(基数为 10): 数字为 0-9。每一位的位值是 10 的幂。
- Binary (Base 2): Digits are 0 and 1. Each place value is a power of 2.
- 二进制(基数为 2): 数字为 0 和 1。每一位的位值是 2 的幂。
- Hexadecimal (Base 16): Digits are 0-9 and A-F (representing 10-15). Each place value is a power of 16.
- 十六进制(基数为 16): 数字为 0-9 以及 A-F(代表 10-15)。每一位的位值是 16 的幂。
For example, in denary: 345 = (3 × 10²) + (4 × 10¹) + (5 × 10⁰)
例如,十进制:345 = (3 × 10²) + (4 × 10¹) + (5 × 10⁰)
2. Converting Between Number Bases | 数制间的转换
To convert denary to binary, repeatedly divide by 2 and read the remainders upwards. To convert binary to hexadecimal, group the binary digits into sets of four starting from the right, and map each group to its hex equivalent.
将十进制转换为二进制,需要反复除以 2 并向上读取余数。要将二进制转换为十六进制,从右开始将二进制数字每四位一组,并将每组映射到对应的十六进制数。
| Denary (十进制) | Binary (二进制) | Hexadecimal (十六进制) |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
Example: Convert denary 13 to binary. 13 ÷ 2 = 6 remainder 1; 6 ÷ 2 = 3 remainder 0; 3 ÷ 2 = 1 remainder 1; 1 ÷ 2 = 0 remainder 1. Reading upwards gives 1101₂.
示例:将十进制 13 转换为二进制。13 ÷ 2 = 6 余 1;6 ÷ 2 = 3 余 0;3 ÷ 2 = 1 余 1;1 ÷ 2 = 0 余 1。向上读取得到 1101₂(即 8+4+1)。
3. Binary Arithmetic and Shifts | 二进制运算与移位
Binary addition follows simple rules. A logical left shift multiplies a binary number by 2 for each shift; a right shift divides it by 2.
二进制加法遵循简单的规则。逻辑左移一位相当于将二进制数乘以 2;右移一位相当于除以 2。
- Rules of binary addition: 0 + 0 = 0; 0 + 1 = 1; 1 + 1 = 0 (carry 1); 1 + 1 + 1 = 1 (carry 1).
- 二进制加法规则: 0 + 0 = 0;0 + 1 = 1;1 + 1 = 0(进 1);1 + 1 + 1 = 1(进 1)。
- Example: Calculate 1001₂ + 0101₂.
- 示例: 计算 1001₂ + 0101₂。
1001₂ + 0101₂ = 1110₂ (which is 9 + 5 = 14)
1001₂ + 0101₂ = 1110₂(即 9 + 5 = 14)
Example: The binary value 0010₂ (2) left-shifted by two places becomes 1000₂ (8), effectively multiplying it by 4.
示例:二进制值 0010₂(2)左移两位变成 1000₂(8),相当于乘以 4。
4. Representing Text: ASCII and Unicode | 文本表示:ASCII 与 Unicode
Text is represented by assigning a unique binary code to each character. ASCII originally used 7 bits to represent 128 characters, later extended to 8 bits for 256 characters. Unicode uses 16 or 32 bits to represent characters from all world languages, including emojis.
文本通过为每个字符分配唯一的二进制代码来表示。ASCII 最初使用 7 位来表示 128 个字符,后来扩展为 8 位以表示 256 个字符。Unicode 使用 16 位或 32 位来表示世界上所有语言的字符,包括表情符号。
| Feature (特征) | ASCII | Unicode |
|---|---|---|
| Bit length (位长) | 7 or 8 bits (7 或 8 位) | 16 or 32 bits (16 或 32 位) |
| Character capacity (字符容量) | 128 or 256 characters (128 或 256 个字符) | Over 1 million characters (超过 100 万个字符) |
| Language support (语言支持) | English and basic symbols (英语和基本符号) | All global languages (全球所有语言) |
For example, the character ‘A’ has an ASCII code of 65, which is 01000001 in 8-bit binary.
例如,字符 ‘A’ 的 ASCII 码是 65,即 8 位二进制形式的 01000001。
5. Representing Images: Bitmap vs Vector | 图像表示:位图与矢量图
Images are either stored as bitmaps or vector graphics. A bitmap is a grid of individual pixels, each with a specific colour. A vector graphic is defined by mathematical formulas and geometric shapes, such as lines, curves, and polygons.
图像存储为位图或矢量图形。位图是由单个像素组成的网格,每个像素都有特定的颜色。矢量图形由数学公式和几何形状(如直线、曲线和多边形)定义。
- Bitmap: Resolution (number of pixels) and colour depth (bits per pixel) determine file size.
- 位图: 分辨率(像素数量)和颜色深度(每像素位数)决定文件大小。
- Vector: Scalable without losing quality; ideal for logos and diagrams.
- 矢量图: 缩放不丢失质量;非常适合徽标和图表。
Bitmap images can lose quality when scaled up because pixels become visible. Vector graphics use less memory for simple shapes but can become complex for photorealistic images.
位图图像在放大时会因为像素可见而丢失质量。矢量图形对于简单形状使用更少内存,但对于逼真的照片图像会变得复杂。
6. Calculating Bitmap File Sizes | 计算位图文件大小
To calculate the file size of a bitmap image, multiply the total number of pixels (width × height) by the colour depth (number of bits used per pixel).
要计算位图图像的文件大小,需要将像素总数(宽 × 高)乘以颜色深度(每个像素使用的位数)。
File Size (bits) = Width × Height × Colour Depth
文件大小(位)= 宽 × 高 × 颜色深度
Example: Calculate the file size of a 100 × 100 pixel image with 24-bit colour. 100 × 100 = 10,000 pixels. 10,000 × 24 = 240,000 bits. To convert to bytes, divide by 8: 240,000 ÷ 8 = 30,000 bytes.
示例:计算一张 100 × 100 像素、24 位颜色的图像文件大小。100 × 100 = 10,000 像素。10,000 × 24 = 240,000 位。转换为字节需除以 8:240,000 ÷ 8 = 30,000 字节。
7. Compression: Lossy and Lossless | 压缩:有损与无损
Compression reduces the number of bits required to represent data, saving storage space and reducing transmission time. There are two main types: lossy and lossless compression.
压缩减少了表示数据所需的位数,节省了存储空间并减少了传输时间。主要有两种类型:有损压缩和无损压缩。
- Lossy Compression: Permanently removes some data, resulting in a smaller file size but a loss of quality. Used for images (JPEG), audio (MP3), and video (MP4).
- 有损压缩: 永久移除部分数据,导致文件更小但质量下降。用于图像(JPEG)、音频(MP3)和视频(MP4)。
- Lossless Compression: Reduces file size without losing any original data. Used for text files and executable programs. Examples include Run-Length Encoding (RLE) and Huffman coding.
- 无损压缩: 在不丢失任何原始数据的情况下减小文件大小。用于文本文件和可执行程序。示例包括游程编码(RLE)和霍夫曼编码。
Lossy compression is suitable for media where minor quality loss is acceptable, but lossless compression is essential for data integrity.
有损压缩适用于质量损失可接受的媒体,但无损压缩对于数据完整性至关重要。
8. Lossless Compression: Run-Length Encoding (RLE) | 无损压缩:游程编码(RLE)
Run-Length Encoding (RLE) is a simple form of lossless compression. It reduces the size of data by replacing sequences of identical repeated characters (or runs) with a single character and the count of how many times it repeats.
游程编码(RLE)是一种简单的无损压缩形式。它通过将连续重复的相同字符(或游程)替换为单个字符及其重复次数来减小数据大小。
Original: AAAAABBBCCCC → Compressed: 5A3B4C
原始数据:AAAAABBBCCCC → 压缩后:5A3B4C
RLE is highly effective for simple graphics, icons, and black-and-white images where long runs of identical pixels are common. It is also used in fax machines.
RLE 对于简单图形、图标和黑白图像非常有效,因为这些图像中常见长串的相同像素。它也用于传真机。
9. Lossless Compression: Huffman Coding | 无损压缩:霍夫曼编码
Huffman coding is a more advanced lossless compression technique. It assigns variable-length binary codes to characters based on their frequency. Frequently occurring characters get shorter codes, while less frequent characters get longer codes.
霍夫曼编码是一种更高级的无损压缩技术。它根据字符的出现频率为其分配可变长度的二进制代码。频繁出现的字符获得较短的代码,而不常出现的字符获得较长的代码。
To build a Huffman code, first count the frequency of each character. Then construct a binary tree by repeatedly merging the two least frequent nodes. Finally, assign ‘0’ to left branches and ‘1’ to right branches.
要构建霍夫曼编码,首先统计每个字符的频率。然后通过反复合并两个频率最低的节点来构建二叉树。最后,为左分支分配 ‘0’,为右分支分配 ‘1’。
For example, consider the string “AABBBC”. Frequencies: A=2, B=3, C=1. A possible Huffman code is: A = 00, B = 1, C = 01. The original string is 6 characters × 8 bits = 48 bits. The compressed string is (2×2) + (3×1) + (1×2) = 4 + 3 + 2 = 9 bits.
例如,考虑字符串 “AABBBC”。频率:A=2,B=3,C=1。一种可能的霍夫曼编码是:A = 00,B = 1,C = 01。原始字符串为 6 个字符 × 8 位 = 48 位。压缩后为 (2×2) + (3×1) + (1×2) = 4 + 3 + 2 = 9 位。
10. Exam Tips and Summary | 考试技巧与总结
To excel in data representation questions, memorise the key formulas and clearly show your working steps. Practice converting between binary, denary, and hexadecimal until it becomes second nature.
要在数据表示相关题目中取得好成绩,请牢记关键公式并清晰展示解题步骤。练习二进制、十进制和十六进制之间的转换,直到得心应手。
- Know your bases: Practice binary addition and logical shifts.
- 掌握数制: 练习二进制加法和逻辑移位。
- Distinguish text encoding: Understand the difference between ASCII and Unicode.
- 区分文本编码: 理解 ASCII 和 Unicode 之间的区别。
- Calculate accurately: File Size = Resolution × Colour Depth. Don’t forget to convert bits to bytes.
- 准确计算: 文件大小 = 分辨率 × 颜色深度。不要忘记将位转换为字节。
- Compare compression types: Justify when to use lossy vs lossless.
- 比较压缩类型: 论证何时使用有损与无损压缩。
Mastering these concepts will help you tackle exam questions related to storage calculations, encoding systems, and data transmission efficiency.
掌握这些概念将帮助你解决与存储计算、编码系统和数据传输效率相关的考试问题。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导