Data Representation: Key Exam Points for IB & WJEC Computer Science | 数据表示:IB 与 WJEC 计算机考点精讲

📚 Data Representation: Key Exam Points for IB & WJEC Computer Science | 数据表示:IB 与 WJEC 计算机考点精讲

Data representation lies at the heart of how computers store, process and transmit information. Whether you are following the IB Computer Science syllabus or preparing for WJEC examinations, mastering binary, hexadecimal, text encoding, image representation, sound sampling and data compression is essential. This article breaks down each topic into coherent bilingual explanations, exam-focused tips and worked examples to boost your confidence.

数据表示是计算机存储、处理与传输信息的核心。无论你学习的是 IB 计算机科学课程还是备考 WJEC 考试,掌握二进制、十六进制、文本编码、图像表示、声音采样和数据压缩都至关重要。本文采用中英双语逐点拆解每个主题,结合考点提示与实例,助你稳步提升应考信心。

1. Why Binary? | 为什么使用二进制?

Computers use binary (base-2) because digital circuits have only two stable states – on and off, represented by 1 and 0. This simplicity makes hardware reliable, cheap and less prone to error. In both IB and WJEC exams, you need to explain the link between logic gates, transistors and binary data.

计算机采用二进制(基数为2)是因为数字电路只有两个稳定状态——开与关,用 1 和 0 表示。这种简单性使硬件更可靠、成本更低且不易出错。在 IB 和 WJEC 考试中,你需要解释逻辑门、晶体管与二进制数据之间的关联。

  • All data types (numbers, text, images, sound) are ultimately stored as sequences of bits.
  • 所有数据类型(数字、文本、图像、声音)最终都存储为比特序列。
  • Binary values correspond directly to voltage levels in a computer’s memory and processor.
  • 二进制值直接对应计算机内存和处理器中的电压电平。

2. Units of Data | 数据单位

Understanding the hierarchy of data units is a common multiple-choice and short-answer topic. A bit (binary digit) is the smallest unit. A nibble is 4 bits, a byte is 8 bits, and larger units follow powers of 2.

理解数据单位的层级是常见的单选题和简答题考点。比特(二进制位)是最小单位。一个半字节是4比特,一个字节是8比特,更大的单位遵循2的幂次。

Unit Abbreviation Size in bytes Power of 2
kilobyte KiB 2¹⁰ bytes 1024 bytes
megabyte MiB 2²⁰ bytes 1,048,576 bytes
gigabyte GiB 2³⁰ bytes 1,073,741,824 bytes

Note: IB and WJEC both distinguish between decimal prefixes (KB = 1000 bytes) and binary prefixes (KiB = 1024 bytes). In storage context, manufacturers often use decimal, while operating systems use binary.

注意:IB 和 WJEC 都区分十进制前缀(KB = 1000 字节)和二进制前缀(KiB = 1024 字节)。在存储语境中,制造商常用十进制,而操作系统使用二进制。


3. Binary and Denary Conversions | 二进制与十进制转换

Converting between binary (base-2) and denary (base-10) is a fundamental skill. Write binary digits under place values that are powers of 2, e.g., 128, 64, 32, 16, 8, 4, 2, 1 for an 8-bit byte. Add the place values where a 1 appears.

二进制(基数为2)与十进制(基数为10)之间的转换是基础技能。在2的幂次位值(例如对于8比特字节:128, 64, 32, 16, 8, 4, 2, 1)下方写出二进制数字,将所有出现1的位值相加。

Example: 01101001₂ → 64 + 32 + 8 + 1 = 105₁₀

例子:01101001₂ → 64 + 32 + 8 + 1 = 105₁₀

For reverse conversion, repeatedly divide by 2 and note remainders; the binary number is the remainders read from bottom to top.

反向转换则反复除以2并记下余数;余数从下往上读取即为二进制数。


4. Hexadecimal System | 十六进制系统

Hexadecimal (base-16) uses digits 0–9 and letters A–F (A=10, B=11, …, F=15). It is a compact way of representing binary, because one hex digit corresponds exactly to 4 bits (a nibble). This makes hex ideal for colour codes, memory addresses and machine code.

十六进制(基数为16)使用数字0-9和字母A-F(A=10, B=11, …, F=15)。它是一种紧凑的二进制表示法,因为一个十六进制位正好对应4个比特(一个半字节)。这使得十六进制非常适用于颜色代码、内存地址和机器码。

Conversion: Group binary bits in fours from right; convert each nibble to its hex equivalent. Example: 1101 0110₂ = D 6₁₆ (13 and 6). Hex to denary: multiply each hex digit by 16ⁿ where n is position from right (starting from 0).

转换方法:将二进制从右向左每四位一组;每组转换为其十六进制等价值。例如:1101 0110₂ = D 6₁₆(13和6)。十六进制转十进制:将每个十六进制位乘以16的n次幂,n为从右数起始位0的位置。


5. Representing Integers – Signed and Unsigned | 整数表示 – 有符号与无符号

Unsigned integers simply store the magnitude using all available bits. For example, an 8-bit unsigned integer can represent 0 to 255 (2⁸ – 1). Signed integers, however, must indicate whether a number is positive or negative. The two most common methods are sign-and-magnitude and two’s complement.

无符号整数直接使用所有可用比特存储数值大小。例如8比特无符号整数可表示0到255(2⁸ – 1)。而有符号整数必须标明正负。最常见的两种方法是符号-幅值表示法和二进制补码。

In sign-and-magnitude, the leftmost bit is the sign (0 = positive, 1 = negative) and the remaining bits store the magnitude. This leads to two representations of zero (+0 and -0) and complicates arithmetic. Two’s complement overcomes this: negative numbers are formed by flipping all bits and adding 1. In 8-bit two’s complement, the range is -128 to +127.

在符号-幅值法中,最左位为符号位(0=正,1=负),其余位存储数值。这会导致零有两种表示(+0和-0),并使算术复杂化。二进制补码解决了这一问题:负数通过将所有位翻转后加1得到。在8位二进制补码中,范围是-128到+127。

WJEC often asks for two’s complement addition and overflow detection; IB may extend this to the concept of absolute addressing and offset representation.

WJEC 常考查二进制补码加法和溢出检测;IB 则可能将其延伸至绝对寻址和偏移表示法的概念。


6. Binary Arithmetic | 二进制算术

Binary addition follows simple rules: 0+0=0, 0+1=1, 1+0=1, 1+1=0 carry 1. You need to perform multi-bit additions and identify whether an overflow occurs (when the result exceeds the bit width). Subtraction is often implemented by adding the two’s complement of the subtrahend.

二进制加法遵循简单规则:0+0=0,0+1=1,1+0=1,1+1=0进位1。你需要进行多比特加法并识别是否发生溢出(当结果超出位宽时)。减法通常通过加上减数的二进制补码来实现。

Multiplication by 2 can be achieved with a left shift; division by 2 with a right shift. Shifts are fundamental to understanding how processors perform fast arithmetic.

乘以2可以通过左移一位实现;除以2可以通过右移一位。移位操作是理解处理器如何快速执行算术运算的基础。

Example (4-bit unsigned): 0110₂ (6) + 0111₂ (7) = 1101₂ (13), no overflow since result within 4-bit range. But for signed two’s complement, adding 0110 (+6) and 0111 (+7) gives 1101 which in 4-bit two’s complement is -3 – an overflow has occurred.

例子(4位无符号):0110₂ (6) + 0111₂ (7) = 1101₂ (13),没有溢出,因为结果在4位范围内。但对于有符号二进制补码,加 0110 (+6) 和 0111 (+7) 得到 1101,在4位补码中为 -3 —— 发生溢出。


7. Representing Text – ASCII, Extended ASCII and Unicode | 文本表示 – ASCII、扩展ASCII与Unicode

Characters are stored as binary codes. Standard ASCII uses 7 bits per character, providing 128 codes (0–127). Extended ASCII uses 8 bits, covering 256 characters, including accented letters and symbols. Unicode was developed to support worldwide languages and symbols, using encoding forms like UTF-8, UTF-16 and UTF-32.

字符以二进制代码形式存储。标准ASCII每个字符使用7比特,提供128个代码(0-127)。扩展ASCII使用8比特,覆盖256个字符,包括重音字母和符号。Unicode 是为支持全球语言和符号而开发的,使用 UTF-8、UTF-16 和 UTF-32 等编码形式。

UTF-8 is variable-length: ASCII characters occupy 1 byte, while others use up to 4 bytes. This backwards compatibility with ASCII makes UTF-8 dominant on the web. In exams, you may be asked to compare ASCII and Unicode, and to justify when Unicode is essential (e.g., multilingual applications).

UTF-8 是可变长度编码:ASCII字符占用1字节,其他字符最多使用4字节。这种与ASCII向后兼容的特性使 UTF-8 在网络上占据主导地位。考试中可能要求比较 ASCII 和 Unicode,并说明 Unicode 在何时必不可少(如多语言应用)。


8. Representing Images – Bitmaps and Vectors | 图像表示 – 位图与矢量图

Images can be represented as bitmaps (raster) or vectors. A bitmap image is a grid of pixels, each pixel’s colour stored as a binary number. Key terms: resolution (pixel dimensions), colour depth (bits per pixel), and file size calculation.

图像可以表示为位图(光栅图)或矢量图。位图图像是一个像素网格,每个像素的颜色存储为一个二进制数。关键术语:分辨率(像素尺寸)、颜色深度(每像素比特数)和文件大小计算。

File size (bits) = width × height × colour depth. For example, a 100×100 pixel image with 24-bit colour (True Colour, 16.7 million colours) uses 100×100×24 = 240,000 bits (30,000 bytes). Metadata (e.g., date, camera model) adds extra size.

文件大小(比特)= 宽 × 高 × 颜色深度。例如,一个100×100像素、24位真彩色图像使用 100×100×24 = 240,000 比特(30,000 字节)。元数据(如日期、相机型号)会额外增加大小。

Vector images store shapes as mathematical descriptions (lines, curves, polygons). They scale without loss of quality and have smaller file sizes for simple diagrams, but are unsuitable for photographs.

矢量图像将形状存储为数学描述(直线、曲线、多边形)。它们缩放无质量损失,简单图形文件尺寸较小,但不适用于照片。


9. Representing Sound – Sampling and Quantisation | 声音表示 – 采样与量化

Sound is an analogue wave; to store it digitally, it must be sampled and quantised. Sampling rate is the number of samples taken per second (measured in Hz). Quantisation is the process of rounding each sample’s amplitude to the nearest binary level, determined by bit depth.

声音是模拟波;要将其数字化存储,必须进行采样和量化。采样率是每秒采集样本的数量(单位为Hz)。量化是根据位深度将每个样本的振幅舍入到最接近的二进制级别的过程。

Higher sample rate captures higher frequencies (Nyquist theorem: sample rate must be at least twice the highest frequency). Higher bit depth (e.g., 16-bit vs 8-bit) gives more dynamic range and less quantisation noise. File size = sample rate × bit depth × duration (in seconds) × number of channels.

较高的采样率可捕捉较高频率(奈奎斯特定理:采样率至少应为最高频率的两倍)。较高的位深度(如16位与8位相比)提供更大的动态范围和更少的量化噪声。文件大小 = 采样率 × 位深度 × 持续时间(秒)× 声道数。

Exam tip: When calculating sound file sizes, always check if the bit depth is given in bits per sample and whether the result is in bits or bytes.

考试提示:计算声音文件大小时,务必检查位深度是否以每样本比特数给出,以及结果是比特还是字节。


10. Data Compression – Lossy vs Lossless | 数据压缩 – 有损与无损

Compression reduces file size to save storage and speed up transmission. Lossless compression allows perfect reconstruction of the original data (e.g., run-length encoding, dictionary methods like ZIP). It is essential for text, code and archival data. Lossy compression permanently discards some information, acceptable for multimedia where perfect fidelity is not required (e.g., JPEG for photos, MP3 for audio).

压缩通过减少文件大小来节省存储并加快传输。无损压缩允许完美重建原始数据(如游程编码、基于字典的方法如ZIP)。它对文本、代码和归档数据至关重要。有损压缩永久丢弃部分信息,适用于无需完美保真的多媒体(如照片用JPEG,音频用MP3)。

Run-length encoding (RLE) replaces repeated data with a count and value. For example, ‘AAAAA’ becomes ‘5A’. It works best with long runs of identical data. Dictionary-based compression (LZW) replaces frequently occurring patterns with shorter codes.

游程编码(RLE)用计数和值替换重复数据。例如 ‘AAAAA’ 变为 ‘5A’。它最适合处理长串相同数据。基于字典的压缩(LZW)用较短的代码替换频繁出现的模式。

In WJEC and IB exams, you may be asked to calculate compression ratios or explain why a particular compression type is suitable for a given scenario.

在 WJEC 和 IB 考试中,你可能需要计算压缩比或解释为何特定压缩类型适合某个给定场景。


11. Error Detection – Parity, Checksums and Check Digits | 错误检测 – 奇偶校验、校验和与校验位

When data is transmitted, errors can occur. Basic error detection methods include parity bits (even or odd), checksums, and check digits. A parity bit is added to make the total number of 1s even (even parity) or odd (odd parity). This can detect single-bit errors but not all multi-bit errors.

数据传输时可能发生错误。基本的错误检测方法包括奇偶校验位(偶校验或奇校验)、校验和以及校验位。添加一个奇偶校验位使所有比特中1的总数为偶数(偶校验)或奇数(奇校验)。这能检测单比特错误,但不能检测所有多比特错误。

Checksums involve adding up data values and sending the sum; the receiver recomputes and compares. It is used in network protocols. Check digits (like ISBN-13, barcodes) are calculated using modular arithmetic to catch input errors.

校验和涉及将数据值相加并发送其总和;接收方重新计算并进行比较。它用于网络协议。校验位(如ISBN-13、条形码)使用模运算计算,以捕捉输入错误。

Important: These methods only detect errors; they do not correct them. For correction, more advanced codes like Hamming codes are needed, which may be mentioned in IB extensions.

重点:这些方法仅能检测错误,不能纠正错误。纠正错误需要更高级的编码如汉明码,IB 扩展部分可能会提及。


12. Logical Binary Shifts and Bitwise Operations | 逻辑移位与按位运算

Logical shifts (left and right) move bits in a register, filling empty positions with zeros. A left shift by n positions multiplies an unsigned integer by 2ⁿ; a right shift divides by 2ⁿ (discarding remainder). These operations are extremely fast and used in low-level optimisation.

逻辑移位(左移和右移)移动寄存器中的比特,用零填充空位。左移 n 位将无符号整数乘以 2ⁿ;右移 n 位将其除以 2ⁿ(舍弃余数)。这些操作速度极快,用于底层优化。

Bitwise AND, OR, XOR and NOT work on individual bits. They are useful for masking (selecting specific bits), toggling flags, and implementing encryption algorithms. In both IB and WJEC, you may be asked to predict the outcome of a given bitwise operation on binary patterns.

按位与、或、异或和非作用于单个比特上。它们对掩码操作(选择特定位)、切换标志位和实现加密算法非常有用。在 IB 和 WJEC 中,你可能会被要求预测给定比特模式经过按位运算后的结果。

Example: 10101100₂ OR 11010011₂ = 11111111₂; 10101100₂ AND 11010011₂ = 10000000₂.

例如:10101100₂ 或 11010011₂ = 11111111₂;10101100₂ 与 11010011₂ = 10000000₂。


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