A-Level Computer Science: Data Representation Essentials | A-Level 计算机:数据表示 考点精讲

📚 A-Level Computer Science: Data Representation Essentials | A-Level 计算机:数据表示 考点精讲

Data representation forms the bedrock of how computers store, process, and transmit information. From the simplest integers to floating-point numbers, text, images, and sound, every piece of data is encoded as binary digits. This article walks you through the core concepts tested in A-Level Computer Science, including number bases, binary arithmetic, character encoding, and compression techniques. Mastering these topics will not only help you ace exam questions but also deepen your understanding of how computing systems work beneath the high-level abstractions.

数据表示是计算机存储、处理和传输信息的基石。从最简单的整数到浮点数、文本、图像和声音,所有数据最终都以二进制数字的形式编码。本文带你梳理 A-Level 计算机科学考试中的核心概念,包括数制、二进制运算、字符编码和压缩技术。掌握这些内容不仅能帮你应对考试,还能加深你对计算系统底层运作的理解。

1. Number Bases and Conversions | 数制与转换

Computers use binary (base 2) because digital circuits have two stable states: on and off. Hexadecimal (base 16) acts as a compact shorthand for binary, with each hex digit representing exactly four bits. Understanding how to convert between denary, binary, and hexadecimal is fundamental to any data representation topic.

计算机使用二进制(基数为 2),因为数字电路有两种稳定状态:开和关。十六进制(基数为 16)作为二进制的紧凑缩写,每个十六进制数字恰好代表四位二进制数。理解如何在十进制、二进制和十六进制之间转换是数据表示的基础。

To convert a denary integer to binary, repeatedly divide by 2 and read the remainders from bottom to top. For example, 25 in denary becomes 11001₂.

要将十进制整数转换为二进制,反复除以 2,从下往上读取余数。例如,十进制 25 转换为二进制是 11001₂。

Converting binary to hexadecimal involves grouping bits into nibbles (groups of four) from the right. Thus 1101 1001₂ becomes D9₁₆.

二进制转十六进制需要从右向左每四位一组进行分组。因此 1101 1001₂ 转换为十六进制是 D9₁₆。

For fractional numbers, use place values to the right of the binary point: ½, ¼, ⅛, etc. 0.101₂ equals 1×½ + 0×¼ + 1×⅛ = 0.625 in denary.

对于小数,使用小数点右侧的位值:½、¼、⅛ 等。0.101₂ 等于 1×½ + 0×¼ + 1×⅛ = 十进制 0.625。


2. Binary Arithmetic | 二进制运算

Addition in binary follows simple rules: 0+0=0, 0+1=1, 1+0=1, and 1+1=10 (write 0, carry 1). Subtraction can be performed using two’s complement addition, which simplifies hardware design.

二进制加法遵循简单规则:0+0=0,0+1=1,1+0=1,1+1=10(写 0,进位 1)。减法可通过二进制补码加法来实现,从而简化硬件设计。

When adding two binary numbers, an overflow occurs if the result exceeds the allocated bit width. For unsigned numbers, overflow is indicated by a carry-out of the most significant bit. For example, adding 1111₁₂ (15) and 0001₂ (1) in a 4-bit register yields 0000₂ with a carry-out 1, indicating overflow.

当两个二进制数相加时,如果结果超出分配的位宽,就会发生溢出。对于无符号数,溢出由最高位的进位表示。例如,在 4 位寄存器中将 1111₂(15)和 0001₂(1)相加,得到 0000₂ 并产生进位 1,表示溢出。

Binary multiplication can be done by repeated addition and shifting, just like long multiplication in denary. Division is typically performed through repeated subtraction or shift-and-subtract algorithms.

二进制乘法可以通过重复加法和移位完成,就像十进制竖式乘法一样。除法通常通过重复减法或移位减法算法实现。


3. Signed Integers: Two’s Complement | 带符号整数:二进制补码

Two’s complement is the most common method for representing signed integers. The most significant bit (MSB) becomes the sign bit: 0 for positive, 1 for negative. The magnitude of a negative number is found by flipping all bits and adding 1.

二进制补码是表示带符号整数最常见的方法。最高位(MSB)成为符号位:0 表示正数,1 表示负数。负数的绝对值可以通过翻转所有位再加 1 得到。

For an n-bit two’s complement representation, the range is from -2ⁿ⁻¹ to 2ⁿ⁻¹ – 1. For 8 bits, the range is -128 to 127. This asymmetric range arises because there is no negative zero.

对于 n 位二进制补码表示,取值范围为 -2ⁿ⁻¹ 到 2ⁿ⁻¹ – 1。对于 8 位,范围是 -128 到 127。这种不对称范围是因为不存在负零。

To subtract B from A, compute A + (two’s complement of B). The carry-out is ignored, and the result is interpreted as a signed value directly. This allows the same adder circuit to be used for both addition and subtraction.

要从 A 减去 B,计算 A + (B 的补码)。忽略最终的进位,结果直接解释为有符号值。这使得同一个加法器电路可用于加法和减法。


4. Floating Point Representation | 浮点数表示

Floating point numbers represent real values using a mantissa and an exponent, analogous to scientific notation. The number is expressed as mantissa × 2^exponent. Both the mantissa and exponent are stored as binary, typically in two’s complement for the exponent.

浮点数使用尾数和指数表示实数,类似于科学记数法。数字表示为 尾数 × 2^指数。尾数和指数都以二进制形式存储,指数通常使用二进制补码。

Increasing the number of bits allocated to the mantissa improves precision, while more bits for the exponent increase the range of representable values. This trade-off is a classic design decision in floating point formats.

增加分配给尾数的位数可以提高精度,而增加指数的位数则扩大了可表示数值的范围。这种权衡是浮点格式设计中的经典决策。

Normalisation ensures a unique representation by adjusting the mantissa so that the first two bits after the sign bit are different (01 or 10). This maximises precision by removing leading zeros or repeated sign bits.

规格化通过调整尾数,使得符号位后的前两位不同(01 或 10),从而保证表示的唯一性。这使得通过移除前导零或重复的符号位来最大化精度。


5. Rounding, Precision, and Errors | 舍入、精度与误差

Real numbers often cannot be represented exactly in binary, leading to rounding errors. Common rounding methods include truncation (chopping off extra bits) and rounding to nearest (adding 1 to the least significant bit if the discarded part is ≥ half).

实数通常无法在二进制中精确表示,从而导致舍入误差。常见的舍入方法包括截断(切掉多余位)和最近舍入(如果舍弃部分 ≥ 一半,则在最低有效位加 1)。

Absolute error is the difference between the actual value and the stored value; relative error is the absolute error divided by the actual value. These errors accumulate in iterative computations, potentially causing significant inaccuracies.

绝对误差是实际值与存储值之间的差值;相对误差是绝对误差除以实际值。这些误差在迭代计算中会累积,可能导致显著的不准确性。

Underflow occurs when a number is too small to be represented, even with the smallest exponent, while overflow occurs when the exponent is too large. In many systems, underflow results in 0 and overflow triggers an exception or results in infinity.

当数字太小,即使使用最小指数也无法表示时,会发生下溢;而当指数过大时会发生溢出。在许多系统中,下溢导致结果为 0,溢出则会触发异常或产生无穷大。


6. Character Encoding | 字符编码

ASCII originally used 7 bits to represent 128 characters, including control codes, digits, uppercase and lowercase letters, and symbols. Extended ASCII added an 8th bit for 256 characters, covering accented letters and additional symbols.

ASCII 最初使用 7 位表示 128 个字符,包括控制码、数字、大小写字母和符号。扩展 ASCII 增加了第 8 位,可表示 256 个字符,涵盖带重音符号的字母和额外符号。

Unicode was designed to encompass all writing systems, with over 143,000 characters. UTF-8, a variable-width encoding, uses 1 byte for ASCII characters and up to 4 bytes for others, ensuring backwards compatibility and efficient storage.

Unicode 的设计目标是涵盖所有书写系统,拥有超过 143,000 个字符。UTF-8 是一种可变宽度编码,对 ASCII 字符使用 1 个字节,对其他字符最多使用 4 个字节,确保向后兼容和高效存储。

Character sets define a mapping between code points and glyphs. Important distinctions: a character set specifies the characters available, while an encoding defines how those code points are stored as bits.

字符集定义了码点和字形之间的映射。重要区别:字符集指定了可用的字符,而编码定义了如何将这些码点以二进制形式存储。


7. Bit Manipulation and Shifts | 位操作与移位

Logical shifts move bits left or right, filling vacated positions with zeros. A left logical shift multiplies an unsigned integer by 2 for each shift; a right logical shift performs unsigned division by 2.

逻辑移位将位向左或向右移动,空出的位置用零填充。每向左逻辑移一位,就将无符号整数乘以 2;每向右逻辑移一位,则进行无符号除法除以 2。

Arithmetic shifts preserve the sign bit when shifting right, filling with copies of the sign bit. This maintains the value’s sign for two’s complement numbers. A right arithmetic shift effectively divides a signed number by 2, rounding towards negative infinity.

算术移位在右移时保留符号位,用符号位的副本填充。这保持了二进制补码数值的符号。算术右移实际上将有符号数除以 2,向负无穷取整。

Cyclic shifts (rotations) move bits around, with the bit that falls off one end reappearing at the other. These are used in cryptography and certain algorithms, but are less common in standard arithmetic.

循环移位将位进行旋转,从一端移出的位重新出现在另一端。它们用于密码学和某些算法,但在标准算术中较少见。


8. Representing Images | 图像表示

Bitmap images consist of a grid of pixels, each assigned a colour value. The resolution defines the number of pixels (e.g., 1920×1080). The colour depth specifies how many bits represent each pixel’s colour, determining the number of unique colours available.

位图图像由像素网格组成,每个像素分配一个颜色值。分辨率定义像素数量(例如 1920×1080)。颜色深度指定每个像素的颜色用多少位表示,决定了可用的唯一颜色数量。

With a colour depth of n bits per pixel, 2ⁿ colours can be represented. Common depths include 8-bit (256 colours), 24-bit (Truecolour, 16.7 million colours), and 32-bit (with an alpha channel for transparency).

若每个像素的颜色深度为 n 位,可表示 2ⁿ 种颜色。常见深度包括 8 位(256 色)、24 位(真彩色,1670 万色)和 32 位(包含用于透明度的 alpha 通道)。

Vector graphics store images as mathematical descriptions of shapes, using primitives like lines, curves, and polygons. They scale without loss of quality and typically have smaller file sizes for diagrams and logos, but are unsuitable for photorealistic imagery.

矢量图形将图像存储为形状的数学描述,使用线条、曲线和多边形等基本元素。它们缩放时不会损失质量,对于图表和徽标通常文件较小,但不适合逼真的摄影图像。


9. Representing Sound | 声音表示

Sound is captured by sampling the amplitude of an analogue signal at regular intervals. The sample rate, measured in Hz, determines how frequently samples are taken. The Nyquist theorem states that the sample rate must be at least twice the highest frequency to avoid aliasing.

声音通过以固定间隔对模拟信号幅度进行采样来捕获。采样率以赫兹为单位,决定了采样的频率。奈奎斯特定理指出,采样率必须至少是最高频率的两倍,以避免混叠。

The bit depth (sample resolution) defines the number of bits used to store each sample’s amplitude. A higher bit depth reduces quantisation error and yields a wider dynamic range. CD quality uses 16 bits per sample at 44.1 kHz.

位深度(采样分辨率)定义了用于存储每个样本幅度的位数。较高的位深度可减少量化误差,并提供更宽的动态范围。CD 音质使用每个样本 16 位、44.1 kHz 的采样率。

The resulting file size can be estimated as: sample rate × bit depth × number of channels × duration (in seconds). For stereo, the number of channels is 2. Compression can reduce this substantially.

生成的文件大小可以估算为:采样率 × 位深度 × 声道数 × 时长(秒)。立体声的声道数为 2。压缩可以大幅减小文件大小。


10. Data Compression | 数据压缩

Lossless compression reduces file size without losing any information, so the original data can be perfectly reconstructed. Examples include run-length encoding (RLE) and Huffman coding. RLE replaces repeated values with a count and value pair, effective for simple graphics with large uniform areas.

无损压缩在不丢失任何信息的情况下减小文件大小,因此可以完美重建原始数据。示例包括游程编码(RLE)和霍夫曼编码。RLE 用计数和值的组合替换重复值,适用于有大面积均匀区域的简单图形。

Huffman coding assigns variable-length codes to symbols based on their frequency of occurrence. Frequently used symbols get shorter codes, reducing overall bit count. This technique is used in formats like ZIP and JPEG.

霍夫曼编码根据符号的出现频率为其分配可变长度编码。常用符号获得较短的编码,从而减少总位数。该技术用于 ZIP 和 JPEG 等格式。

Lossy compression achieves much higher compression ratios by permanently discarding less-perceptible information. JPEG for images removes high-frequency colour variations, while MP3 for audio uses psychoacoustic models to cut sounds humans barely hear.

有损压缩通过永久舍弃不易察觉的信息来实现更高的压缩比。图像 JPEG 去除了高频颜色变化,而音频 MP3 使用心理声学模型删去人耳几乎听不到的声音。


11. Error Detection and Correction | 差错检测与纠正

Parity bits add a single bit to a binary string to make the total number of 1s even (even parity) or odd (odd parity). Simple parity can detect a single-bit error but cannot correct it, and fails to detect an even number of bit flips.

奇偶校验位在二进制串中添加一个位,使 1 的总数为偶数(偶校验)或奇数(奇校验)。简单的奇偶校验可以检测单比特错误但不能纠正,且无法检测偶数个位翻转。

Checksums calculate a numeric sum of the data; the receiver recomputes the sum and compares it with the transmitted checksum. While more robust than parity, they may still miss complex error patterns.

校验和计算数据的数值总和;接收方重新计算总和并与传输的校验和比较。虽然比奇偶校验更可靠,但仍可能遗漏复杂的错误模式。

Cyclic Redundancy Check (CRC) treats the data as a polynomial and divides it by a generator polynomial, appending the remainder as a check value. CRC is widely used in networked communication and storage devices due to its strong error-detection capability.

循环冗余校验(CRC)将数据视为多项式,并除以生成多项式,将余数附加为校验值。CRC 因其强大的差错检测能力而广泛用于网络通信和存储设备。


Published by TutorHao | Computer Science Revision Series | aleveler.com

更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version