📚 Data Representation and Operation in A-Level Computing | A-Level计算机:数据表示与操作全解析
Data representation and manipulation form the foundation of the Cambridge International A-Level Computer Science syllabus (9618). This article provides a comprehensive guide to how data is stored, interpreted, and processed inside a computer, covering binary arithmetic, two’s complement, floating-point numbers, character encoding, and bitwise operations.
数据表示与操作是剑桥国际A-Level计算机科学考纲(9618)的核心基础。本文将全面解析数据在计算机内部的存储方式、解释方法及处理流程,涵盖二进制算术、二进制补码、浮点数、字符编码与按位运算等核心考点。
1. The Binary Number System | 二进制数制
Computers use the binary system because electronic circuits have only two stable states: on (1) and off (0). Every piece of data — numbers, text, images, sound — is ultimately stored as a sequence of bits. A single bit represents either 0 or 1; eight bits form one byte.
计算机采用二进制数制,是因为电子电路只有两种稳定状态:开(1)和关(0)。所有数据——无论是数字、文本、图像还是声音——最终都以比特序列的形式存储。单个比特表示0或1;八个比特组成一个字节。
In the binary system, the position of each digit determines its weight. For example, the binary number 1011₂ can be expanded as:
在二进制系统中,每个数字的位置决定了它的权重。例如,二进制数1011₂可以展开为:
1011₂ = 1 × 2³ + 0 × 2² + 1 × 2¹ + 1 × 2⁰ = 8 + 0 + 2 + 1 = 11₁₀
This positional notation is identical in structure to the decimal system, but the base is 2 rather than 10. A-Level questions often require conversion between binary, denary, and hexadecimal, as well as performing arithmetic directly in binary.
这种位权记数法与十进制在结构上完全一致,只是基数是2而非10。A-Level试题经常要求学生在二进制、十进制和十六进制之间进行转换,并直接在二进制中进行运算。
Hexadecimal (base 16) is widely used as a compact shorthand for binary. Each hexadecimal digit corresponds to exactly four binary bits, making conversion trivial:
十六进制(基数为16)常作为二进制的紧凑简写形式。每一位十六进制数字恰好对应四位二进制比特,使得两者之间转换极为简便:
A₍₁₆₎ = 1010₂ = 10₁₀
2. Binary Arithmetic | 二进制算术
Binary addition follows the same principles as decimal addition, but with only four possible rules. When two bits sum to 2 (10₂), a carry of 1 is generated to the next column to the left.
二进制加法遵循与十进制加法相同的原理,但只有四种可能的规则。当两个比特之和为2(即10₂)时,需要向左边一列产生一个进位1。
- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 1 = 0, carry 1
- 1 + 1 + 1 (with carry) = 1, carry 1
For example, adding 5₁₀ (0101₂) and 7₁₀ (0111₂):
例如,计算5₁₀(0101₂)加7₁₀(0111₂):
0101₂ + 0111₂ = 1100₂ = 12₁₀
Binary subtraction can be performed using the borrow method, but in modern computer systems it is more commonly implemented using two’s complement addition, which converts subtraction into an addition problem. This approach eliminates the need for separate subtraction circuitry.
二进制减法可以使用借位法计算,但现代计算机系统中更常采用二进制补码的加法来实现减法,将减法转换为加法问题。这种方法免去了单独的减法电路设计。
Exam questions frequently ask students to detect overflow in binary addition. Overflow occurs when the result exceeds the range that the fixed number of bits can represent. For n-bit unsigned numbers, the range is 0 to 2ⁿ − 1.
考试题目经常要求学生在二进制加法中检测溢出。当结果超出固定位数所能表示的范围时,就会发生溢出。对于n位无符号数,其范围是0到2ⁿ − 1。
3. Two’s Complement Representation | 二进制补码表示
To represent negative integers in binary, computer systems use two’s complement notation. The most significant bit (MSB) serves as the sign bit: 0 indicates positive, 1 indicates negative. For an n-bit two’s complement number, the range of representable values is −2ⁿ⁻¹ to +2ⁿ⁻¹ − 1.
为了在二进制中表示负整数,计算机系统采用二进制补码记法。最高有效位(MSB)作为符号位:0表示正数,1表示负数。对于n位二进制补码数,可表示的数值范围是−2ⁿ⁻¹到+2ⁿ⁻¹ − 1。
To convert a positive binary number to two’s complement negative form:
将正二进制数转换为二进制补码负数形式的步骤如下:
- Step 1: Write the positive number in binary.
- Step 1(第一步):用二进制写出正数。
- Step 2: Invert every bit (0 becomes 1, 1 becomes 0).
- Step 2(第二步):将所有比特取反(0变为1,1变为0)。
- Step 3: Add 1 to the inverted result.
- Step 3(第三步):在取反结果上加1。
For example, representing −6₁₀ as an 8-bit two’s complement number:
例如,将−6₁₀表示为8位二进制补码数:
6₁₀ = 00000110₂ → invert → 11111001₂ → add 1 → 11111010₂
Thus, −6 in 8-bit two’s complement is 11111010₂. To verify, add the positive and negative forms: 00000110₂ + 11111010₂ = 100000000₂, where the leading 1 is discarded, yielding 00000000₂ (zero).
因此,−6在8位二进制补码中表示为11111010₂。验证方法是将正负形式相加:00000110₂ + 11111010₂ = 100000000₂,其中最高位的1被丢弃,得到00000000₂(即零)。
A critical exam skill is converting a negative denary number to two’s complement and back. Remember that the two’s complement of a two’s complement number always returns the original value — a useful self-checking property.
一个关键的考试技能是负十进制数与二进制补码之间的相互转换。记住:对二进制补码再次求补总会得到原始值——这是一个非常有用的自我检验性质。
4. Floating-Point Representation | 浮点数表示
Real numbers cannot always be stored precisely in binary form. A-Level Computer Science uses a simplified floating-point model with two components: a mantissa and an exponent. The value is calculated as:
实数并不总能以二进制形式精确存储。A-Level计算机科学采用简化的浮点模型,由两个部分组成:尾数(mantissa)和指数(exponent)。其值计算如下:
Value = Mantissa × 2^Exponent
In a typical CIE-style question, the first few bits represent the mantissa and the remaining bits represent the exponent. Both are usually stored in two’s complement form. For example, consider a 10-bit floating-point number with 6 bits of mantissa and 4 bits of exponent:
在典型的CIE风格题目中,前面若干比特表示尾数,其余比特表示指数。两者通常都以二进制补码形式存储。例如,考虑一个10位浮点数,其中6位为尾数,4位为指数:
0.10110₂ × 2^0011₂
Here, the mantissa 0.10110₂ represents a value between 0.5 and 1 because the binary point is assumed to be immediately after the sign bit. The exponent 0011₂ equals 3₁₀, so the stored value is 0.10110₂ × 2³ = 101.1₂ = 5.5₁₀.
这里,尾数0.10110₂表示0.5到1之间的值,因为二进制小数点被假定在符号位之后。指数0011₂等于3₁₀,因此存储的数值为0.10110₂ × 2³ = 101.1₂ = 5.5₁₀。
When normalising a floating-point number, the mantissa is shifted so that the first two bits after the sign bit are different (1 followed by 0 for positive numbers). This maximises precision for a given number of bits. For example, the unnormalised mantissa 0.001010₂ can be normalised to 0.101000₂ by shifting left twice and reducing the original exponent by 2.
归一化浮点数时,需要将尾数移位,使符号位后的前两位不同(正数为1后接0)。这可在给定比特数下最大化精度。例如,未归一化的尾数0.001010₂可以通过左移两次并相应将指数减2,归一化为0.101000₂。
Exam questions often ask for the range and precision of floating-point representations, or require candidates to normalise a number. A common mistake is forgetting to adjust the exponent when shifting the mantissa.
考试题目经常要求分析浮点数表示的数值范围和精度,或要求考生对数字进行归一化。一个常见错误是在移位尾数时忘记相应调整指数。
5. Character Encoding | 字符编码
Characters are stored as binary codes, and international standards define the mapping between characters and code points.
字符以二进制编码存储,国际标准定义了字符与码点之间的映射关系。
| Encoding Scheme | Bits per Character | Capacity | Coverage |
| ASCII | 7 bits | 128 codes | English letters, digits, punctuation, control characters |
| Extended ASCII | 8 bits | 256 codes | Adds accented characters and box-drawing symbols |
| Unicode (UTF-8) | 8–32 bits (variable) | Over 1.1 million code points | All major writing systems, emoji, mathematical symbols |
ASCII (American Standard Code for Information Interchange) uses 7 bits and can therefore represent 2⁷ = 128 distinct characters. The letter ‘A’ has ASCII code 65₁₀ (1000001₂), and ‘a’ has code 97₁₀. Note that uppercase and lowercase letters are separated by exactly 32 in denary.
ASCII(美国信息交换标准代码)使用7位,因此可以表示2⁷ = 128个不同字符。字母’A’的ASCII码为65₁₀(1000001₂),’a’的码为97₁₀。注意大写与小写字母之间恰好相差32(十进制)。
Unicode is a superset of ASCII in its compatibility with the first 128 code points, and UTF-8 uses variable-length encoding to store characters efficiently. Exam questions frequently ask students to explain why Unicode is necessary and how it differs from ASCII.
Unicode在其前128个码点与ASCII保持完全兼容,UTF-8采用变长编码以高效存储字符。考试问题经常要求学生解释为什么需要Unicode以及它与ASCII的区别。
6. Bitwise Operations | 按位运算
Bitwise operations manipulate individual bits within a binary number. The four fundamental operations are AND, OR, XOR, and NOT. These operations are performed on corresponding bits of two operands.
按位运算对二进制数中的各个比特进行独立操作。四种基本运算是AND(与)、OR(或)、XOR(异或)和NOT(非)。这些运算对两个操作数的对应比特分别进行操作。
- AND: Result is 1 only when both input bits are 1.
- AND(与):仅当两个输入比特都为1时,结果为1。
- OR: Result is 1 when at least one input bit is 1.
- OR(或):当至少一个输入比特为1时,结果为1。
- XOR: Result is 1 when the input bits are different.
- XOR(异或):当输入比特不同时,结果为1。
- NOT: Result is the inverse of the single input bit.
- NOT(非):结果是单个输入比特的反码。
For example, computing the XOR of 1010₂ and 0110₂:
例如,计算1010₂与0110₂的XOR结果:
1010₂ XOR 0110₂ = 1100₂
A classic practical application of XOR is masking: to flip a specific bit, XOR it with a 1 at that position; to keep it unchanged, XOR it with a 0. Bitwise AND is often used to clear specific bits (masking with 0) or to test whether a particular bit is set (AND with a mask containing 1 at that position).
XOR的一个经典实际应用是掩码(masking):要翻转某一位,只需将该位与1进行XOR;要保持该位不变,则与0进行XOR。按位AND则常用于清除特定位(与0进行掩码)或测试某一位是否被置位(与在该位置为1的掩码进行AND)。
In the CIE syllabus, candidates must be able to trace and construct logic circuits using the equivalent gate symbols, and to write truth tables for combinations of these operations.
在CIE考纲中,考生必须能够用等效的门符号追踪和构建逻辑电路,并为这些运算的组合列出真值表。
7. Shift Operations | 移位操作
Shift operations move all bits in a register left or right by a specified number of positions. Two types of shifts are typically examined: logical shift and arithmetic shift.
移位操作将寄存器中的所有比特按指定位置数向左或向右移动。考试通常涉及两种移位类型:逻辑移位(logical shift)和算术移位(arithmetic shift)。
Logical shift fills the vacated positions with 0s. A logical left shift by one position multiplies an unsigned number by 2, while a logical right shift by one position divides it by 2 (integer division). For example:
逻辑移位用0填充空出的位置。逻辑左移一位会使无符号数乘以2,而逻辑右移一位则使其除以2(整除)。例如:
00011001₂ (25₁₀) logical left shift 1 → 00110010₂ (50₁₀)
Arithmetic shift, on the other hand, preserves the sign bit (MSB). For negative numbers stored in two’s complement, an arithmetic right shift retains the sign bit’s value in the newly vacated position, effectively performing division by 2 while keeping the number negative.
算术移位则保持符号位(MSB)不变。对于以二进制补码存储的负数,算术右移在空出的位置上保持符号位的值,从而在保持负数的同时实现除以2的操作。
11100110₂ (−26₁₀) arithmetic right shift 1 → 11110011₂ (−13₁₀)
A common exam task is distinguishing between the effects of logical and arithmetic shifts on signed numbers. A logical right shift on a negative number would corrupt its sign, converting it into a large positive value.
一个常见的考试任务是区分逻辑移位和算术移位对有符号数的影响。对负数进行逻辑右移会破坏其符号位,将其转换为一个很大的正值。
8. Memory Operations | 主存储器操作
Data in main memory is accessed using address-based operations. The two fundamental actions are read (load) and write (store). During a read operation, the CPU places the memory address on the address bus, and after the memory returns the data, it is placed on the data bus.
主存储器中的数据通过基于地址的操作来访问。两个基本动作是读取(load)和写入(store)。在读取操作期间,CPU将内存地址放到地址总线上,内存返回数据后,数据被放置到数据总线上。
The relationship between address bus width and maximum addressable memory is a key concept. For a system with an n-bit address bus, the maximum number of addressable memory locations is 2ⁿ. A 16-bit address bus can therefore address up to 2¹⁶ = 65,536 memory locations.
地址总线宽度与最大可寻址内存之间的关系是一个关键概念。对于具有n位地址总线的系统,最大可寻址内存位置数是2ⁿ。因此,16位地址总线最多可寻址2¹⁶ = 65,536个内存位置。
The data bus width determines how many bits can be transferred between the CPU and memory in a single operation. An 8-bit data bus transfers one byte at a time, while a 64-bit data bus transfers eight bytes at once — significantly speeding up memory access.
数据总线宽度决定了CPU与内存之间单次操作能够传输的比特数。8位数据总线一次传输一个字节,而64位数据总线一次可传输八个字节——显著加快了内存访问速度。
Candidates should be able to calculate the total storage capacity of a memory system given the address bus width and data bus width. For example, a system with a 32-bit address bus and 16-bit data bus can access up to 2³² × 16 bits = 8 GiB of memory.
考生应能根据地址总线宽度和数据总线宽度计算内存系统的总存储容量。例如,具有32位地址总线和16位数据总线的系统最多可访问2³² × 16位 = 8 GiB的内存。
9. Data Storage Units | 数据存储单位
Understanding the hierarchy of data units is essential for answering questions on memory capacity and file sizes. The standard units used in the CIE syllabus are:
理解数据单位的层级对于回答关于内存容量和文件大小的问题至关重要。CIE考纲中使用的标准单位如下:
| Unit | Size (binary) | Approximate Denary |
| 1 Kilobyte (KiB) | 2¹⁰ bytes = 1024 bytes | ~10³ bytes |
| 1 Megabyte (MiB) | 2²⁰ bytes = 1,048,576 bytes | ~10⁶ bytes |
| 1 Gigabyte (GiB) | 2³⁰ bytes | ~10⁹ bytes |
| 1 Terabyte (TiB) | 2⁴⁰ bytes | ~10¹² bytes |
When calculating image file sizes, the formula is: width × height × colour depth (bits per pixel) = file size in bits. For sound files: sampling rate × sample resolution × duration = file size in bits.
计算图像文件大小时,公式为:宽度 × 高度 × 颜色深度(每个像素的比特数)= 以比特为单位的文件大小。对于声音文件:采样率 × 采样分辨率 × 持续时间 = 以比特为单位的文件大小。
For example, a 1024 × 768 image with 24-bit true colour requires 1024 × 768 × 24 = 18,874,368 bits ≈ 2.25 MiB. Candidates should always divide by 8 to convert bits to bytes first, then apply the appropriate binary prefix.
例如,一张1024 × 768、24位真彩色的图像需要1024 × 768 × 24 = 18,874,368比特 ≈ 2.25 MiB。考生应始终先将比特数除以8转换为字节,然后再应用适当的二进制前缀。
10. Common Pitfalls and Exam Tips | 常见陷阱与应试指南
Students frequently lose marks on data representation questions due to avoidable errors. The following pitfalls are the most commonly observed in CIE examinations:
学生常因可避免的错误而在数据表示题目中失分。以下是在CIE考试中最常见的陷阱:
- Confusing logical and arithmetic shifts: Always check whether the number is signed. A logical right shift on a two’s complement negative number destroys the sign.
- 混淆逻辑移位和算术移位:始终检查数字是否有符号。对二进制补码负数进行逻辑右移会破坏符号位。
- Forgetting to adjust the exponent during normalisation: Shifting the mantissa by k places requires subtracting k from the exponent.
- 归一化时忘记调整指数:尾数移位k位需要在指数中减去k。
- Ignoring overflow: When the sum of two positive binary numbers exceeds the maximum representable value, the result is invalid.
- 忽略溢出:当两个正二进制数之和超过最大可表示值时,结果是无效的。
- Mixing up bits and bytes: Divide by 8 at the correct stage of file size calculations.
- 混淆比特与字节:在文件大小计算中应在正确的阶段除以8。
- Scope errors in two’s complement: For an n-bit system, the most negative value is −2ⁿ⁻¹, and the most positive is 2ⁿ⁻¹ − 1.
- 二进制补码范围错误:对于n位系统,最小负数为−2ⁿ⁻¹,最大正数为2ⁿ⁻¹ − 1。
When answering examination questions, always show your working. For normalisation, state both the original mantissa/exponent and the normalised pair. For floating-point calculations, explicitly indicate the position of the binary point. Writing intermediate steps clearly not only earns method marks but also helps you detect errors before submitting.
回答考试问题时,务必展示计算过程。对于归一化,同时写出原始尾数/指数和归一化后的配对。对于浮点计算,明确指出二进制小数点的位置。清晰写出中间步骤不仅有助于获得方法分,还能帮助你在提交前发现错误。
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课程辅导,国外大学本科硕士研究生博士课程论文辅导