📚 Binary Essentials for CCEA A-Level Computer Science | CCEA A-Level 计算机:二进制考点精讲
Binary forms the bedrock of all modern computing. For the CCEA A-Level Computer Science specification, a thorough understanding of binary representation, arithmetic, and related concepts is absolutely critical. This article breaks down every key topic you need to master, from the binary number system itself to floating‑point representation and normalisation, with clear explanations and worked examples in both English and Chinese.
二进制是现代计算技术的基石。对于 CCEA A‑Level 计算机科学课程,透彻理解二进制表示、运算及相关概念至关重要。本文将从二进制数制本身讲起,一直到浮点表示与规格化,逐一拆解你必须掌握的核心考点,并提供清晰的中英双语讲解与示例。
1. The Binary Number System and Place Value | 二进制数制与位权
In the binary system, only two digits exist: 0 and 1. Each position in a binary number carries a weight that is a power of two, increasing from right to left. The least significant bit (LSB) is 2⁰, then 2¹, 2², and so on. For example, the binary number 1101₂ represents (1 × 2³) + (1 × 2²) + (0 × 2¹) + (1 × 2⁰) = 13 in decimal.
二进制系统中只有两个数码:0 和 1。二进制数中每一位的权值都是 2 的幂,从右向左依次增大。最低有效位(LSB)为 2⁰,然后是 2¹、2² 等。例如,二进制数 1101₂ 表示 (1 × 2³) + (1 × 2²) + (0 × 2¹) + (1 × 2⁰) = 十进制中的 13。
Understanding place value is fundamental for conversions and arithmetic. There is no digit ‘2’ in binary, so when counting, you carry over to the next higher place just as you carry in decimal when reaching ten.
理解位权是进行数制转换与运算的基础。二进制中没有数码“2”,因此在计数时,就像十进制逢十进一一样,逢二就要向高位进位。
2. Converting Binary to Decimal and Decimal to Binary | 二进制与十进制的相互转换
To convert a binary number to decimal, multiply each bit by its corresponding power of two and sum the results. For binary 101101₂: (1×32) + (0×16) + (1×8) + (1×4) + (0×2) + (1×1) = 32 + 8 + 4 + 1 = 45₁₀.
将二进制转换为十进制时,用每一位乘以对应的 2 的幂然后求和。对于二进制数 101101₂:(1×32) + (0×16) + (1×8) + (1×4) + (0×2) + (1×1) = 32 + 8 + 4 + 1 = 45₁₀。
To convert a decimal integer to binary, use the repeated division‑by‑2 method: divide the number by 2, record the remainder (0 or 1), then divide the quotient by 2, repeating until the quotient is zero. Read the remainders from bottom to top to obtain the binary equivalent. For example, 45 divided by 2 gives quotients: 22, 11, 5, 2, 1, 0 with remainders 1, 0, 1, 1, 0, 1 – reading upwards yields 101101₂.
将十进制整数转换为二进制时,采用除 2 取余法:将数除以 2,记录余数(0 或 1),再将商除以 2,重复直到商为 0。从下往上读取余数即为二进制结果。例如,45 除以 2 依次得到商:22、11、5、2、1、0,余数依次为 1、0、1、1、0、1——从下往上读得 101101₂。
For fractional numbers, multiply the fraction repeatedly by 2, noting the integer part (carry) each time, until the fractional part becomes zero or the desired precision is reached.
对于小数部分,采用乘 2 取整法:反复将小数部分乘以 2,记录每次的整数进位,直到小数部分为零或达到所需精度。
3. The Hexadecimal Number System and Its Role | 十六进制数制及其作用
Hexadecimal (base‑16) uses digits 0‑9 and letters A‑F to represent values 10‑15. This system provides a compact way to express binary values because each hex digit corresponds directly to a group of four bits (a nibble). For example, 1101 0011₂ becomes D3₁₆.
十六进制(基数为 16)使用数字 0‑9 和字母 A‑F 来表示数值 10‑15。这种数制可以紧凑地表达二进制值,因为每个十六进制数码恰好对应四位二进制位(一个半字节)。例如,1101 0011₂ 写成十六进制为 D3₁₆。
Hexadecimal is widely used to represent memory addresses, colour codes, and machine instructions. Converting between binary and hexadecimal is straightforward: split the binary string into groups of four bits (from the right), then replace each group with its hex equivalent. To convert hex to decimal, multiply each digit by its place value (16ⁿ) and sum.
十六进制广泛用于表示内存地址、颜色码和机器指令。二进制与十六进制之间的转换非常简单:将二进制串从右向左每四位一组分开,然后将每组替换为相应的十六进制数码。将十六进制转换为十进制时,用每一位乘以对应的位权(16 的幂)然后求和。
4. Binary Addition and Overflow | 二进制加法与溢出
Binary addition follows the same principles as decimal addition but with only four basic rules: 0+0=0, 0+1=1, 1+0=1, 1+1=10₂ (which is 0 with a carry of 1). When adding two bits plus a carry‑in, 1+1+1=11₂ (which is 1 with a carry of 1).
二进制加法遵循与十进制加法相同的原理,但只有四条基本规则:0+0=0,0+1=1,1+0=1,1+1=10₂(即本位为 0,进位为 1)。当两个二进制位再加上进位输入时,1+1+1=11₂(本位为 1,进位为 1)。
An overflow occurs when the result of an addition exceeds the range that can be represented with the given number of bits. In a fixed‑width representation, if there is a carry out of the most significant bit (MSB) that cannot be stored, the result is incorrect and the overflow flag is set. For example, in an 8‑bit system, adding 127 (01111111₂) and 1 (00000001₂) produces 10000000₂, which is -128 in two’s complement – overflow has occurred.
当加法结果超出给定位数所能表示的范围时,就会发生溢出。在固定宽度表示中,如果最高有效位(MSB)产生无法存储的进位,结果就是错误的,且溢出标志会被置位。例如,在 8 位系统中,将 127(01111111₂)与 1(00000001₂)相加得到 10000000₂,即在补码中表示 -128——此时发生了溢出。
The CCEA specification expects you to identify overflow conditions, particularly in two’s complement arithmetic, by checking whether the carry into the MSB and the carry out of the MSB are different.
CCEA 大纲要求你能够识别溢出条件,尤其是在二进制补码运算中,方法是检查进入 MSB 的进位与从 MSB 出来的进位是否不同。
5. Logical Shifts and Arithmetic Shifts | 逻辑移位与算术移位
Logical shifts move all bits left or right and fill the vacated positions with zeros. A left logical shift by one place multiplies the number by 2 (provided no overflow), while a right logical shift divides an unsigned number by 2. For example, 00110100₂ (52) shifted left logically gives 01101000₂ (104).
逻辑移位将所有位向左或向右移动,并用 0 填充空出的位。向左逻辑移一位相当于将数乘以 2(假设不溢出),而向右逻辑移位相当于将无符号数除以 2。例如,00110100₂(52)左移一位得到 01101000₂(104)。
Arithmetic shifts are designed to preserve the sign of a number in two’s complement. An arithmetic shift right replicates the sign bit (MSB) instead of filling with zero; this preserves the number’s sign and effectively divides by 2 while rounding down. For instance, 11100100₂ (-28 in two’s complement) shifted arithmetic right becomes 11110010₂ (-14).
算术移位用于在二进制补码中保留数的符号。右算术移位复制符号位(MSB)而不是填充 0;这可以保留数的符号,同时相当于除以 2 并向下取整。例如,11100100₂(补码中的 -28)右算术移位后变为 11110010₂(-14)。
A left arithmetic shift is identical to a left logical shift, but an overflow must be detected if the sign bit changes. Both types of shift are essential in low‑level operations and are often examined in the context of multiplication/division and bit manipulation.
左算术移位与左逻辑移位相同,但如果符号位发生变化则必须检测溢出。这两类移位在底层操作中十分关键,常在乘除法或位操作相关的试题中出现。
6. Representing Negative Numbers: Sign and Magnitude vs Two’s Complement | 表示负数:原码与补码
Sign and magnitude representation uses the most significant bit as a sign bit (0 for positive, 1 for negative) and the remaining bits for the magnitude. For instance, in an 8‑bit system, +25 is 00011001₂, while -25 is 10011001₂. This scheme leads to two zeros (00000000₂ and 10000000₂) and complicates arithmetic circuits.
原码表示法使用最高位作为符号位(0 表示正,1 表示负),其余位表示数值大小。例如,在 8 位系统中,+25 为 00011001₂,而 -25 为 10011001₂。这种方案会导致出现两个零(00000000₂ 和 10000000₂),并使运算电路复杂化。
Two’s complement is the standard method used in modern computers. To obtain the two’s complement representation of a negative number, first write the binary for its positive magnitude, then invert all bits (one’s complement), and finally add 1. For example, to represent -25 in 8‑bit two’s complement:
二进制补码是现代计算机使用的标准方法。要获得负数的补码表示,先写出其正值对应的二进制,然后将所有位取反(得到反码),最后在最低位加 1。例如,求 -25 的 8 位补码表示:
+25 → 00011001₂ → Invert → 11100110₂ → Add 1 → 11100111₂
In two’s complement, the MSB carries a negative weight (-2ⁿ⁻¹), which allows a single representation for zero and simplifies addition and subtraction, as subtracting can be done by adding the two’s complement.
在补码表示法中,MSB 带有负权值(-2ⁿ⁻¹),这使得零的表示唯一,并简化了加减法运算,因为可以通过加上补码来实现减法。
7. Range and Overflow in Two’s Complement | 补码中的表示范围与溢出
For an n‑bit two’s complement representation, the range of representable integers is from -2ⁿ⁻¹ to 2ⁿ⁻¹ – 1. For 8‑bit, this is -128 to 127. It is critical to know that the most negative number has no positive counterpart in a fixed width; attempting to negate -128 yields 10000000₂ again, which indicates overflow.
对于 n 位二进制补码表示,可表示的整数范围是 -2ⁿ⁻¹ 到 2ⁿ⁻¹ – 1。对于 8 位,即 -128 到 127。需要特别注意的是,最负的那个数在固定宽度内没有对应的正数;对 -128 取负会再次得到 10000000₂,这就意味着发生了溢出。
Overflow detection in two’s complement addition involves comparing the carry into the MSB with the carry out of the MSB: if they differ, overflow has occurred. This is tested by the XOR of these two carries.
补码加法的溢出检测需要比较进入 MSB 的进位与从 MSB 出来的进位:如果二者不同,则发生了溢出。这可以通过这两个进位的异或运算来检测。
Understanding the range helps programmers choose appropriate data types and anticipate potential overflow bugs, a common exam theme.
理解表示范围有助于程序员选择合适的数据类型并预判潜在的溢出错误,这是常见的考试主题。
8. Floating Point Representation: Mantissa and Exponent | 浮点表示:尾数与阶码
Real numbers are stored using floating point representation, which consists of a mantissa (fractional part) and an exponent. A binary floating point number is expressed as ± mantissa × 2ᵉˣᵖᵒⁿᵉⁿᵗ. Both are stored in a fixed number of bits, with the mantissa typically normalised and in two’s complement form for the fractional part.
实数使用浮点表示法存储,它包含尾数(小数部分)和阶码。一个二进制浮点数表示为 ± 尾数 × 2ᵉˣᵖᵒⁿᵉⁿᵗ。两者都存储在固定位数中,尾数通常要规格化,并且小数部分采用补码形式。
For example, a 16‑bit floating point format might allocate 10 bits for the mantissa (including sign) and 6 bits for the exponent (also in two’s complement). The binary point is assumed to lie immediately after the sign bit of the mantissa. The number 11.25₁₀ = 1011.01₂ can be expressed as 0.101101 × 2⁴, with mantissa 0.101101000 and exponent 000100 (assuming two’s complement exponent).
例如,一种 16 位浮点格式可能为尾数分配 10 位(含符号位),为阶码分配 6 位(同样用补码)。假定二进制小数点在尾数符号位之后。十进制数 11.25 = 1011.01₂ 可表示为 0.101101 × 2⁴,尾数为 0.101101000,阶码为 000100(假设阶码为补码)。
Increasing the number of bits in the mantissa improves precision, while increasing the bits in the exponent extends the range. CCEA exam questions often ask you to convert between decimal, binary floating point, and normalised forms.
增加尾数的位数可提高精度,而增加阶码的位数则可扩大表示范围。CCEA 考题常要求你在十进制、二进制浮点数和规格化形式之间相互转换。
9. Normalisation of Floating Point Numbers | 浮点数的规格化
Normalisation ensures that floating point numbers are stored in a unique, efficient form that maximises precision. In binary, a positive normalised mantissa must start with 0.1 (i.e. the first two bits are 01), while a negative normalised mantissa in two’s complement must start with 1.0 (first two bits 10). This arrangement guarantees the most significant bit of the magnitude is immediately after the binary point.
规格化确保浮点数以唯一且高效的形式存储,使精度最大化。在二进制中,正数的规格化尾数必须以 0.1 开头(即前两位为 01),而用补码表示的负数规格化尾数必须以 1.0 开头(前两位为 10)。这种安排可以确保数值的最高有效位紧跟在二进制小数点之后。
Consider the unnormalised mantissa 0.0001101₂. To normalise, shift the binary point to the right until the first 1 appears after the point, and decrement the exponent by the number of shifts. Here the mantissa becomes 0.1101 and the exponent decreases by 3. Conversely, if you shift the point left, you increase the exponent.
考虑非规格化的尾数 0.0001101₂。要规格化,需要向右移动二进制小数点直到第一个 1 出现在小数点之后,同时阶码减去相应的移动位数。此处尾数变为 0.1101,阶码减少 3。反之,若向左移动小数点,则增加阶码。
Normalisation is crucial because it prevents multiple representations of the same number and avoids wasted bits on leading zeros in the mantissa.
规格化至关重要,因为它避免了同一数字出现多种表示,并防止在尾数的前导零上浪费位数。
10. Converting Floating Point Representation to Decimal and Vice Versa | 浮点表示与十进制互换
To convert a decimal real number to binary floating point, first convert the integer and fractional parts to binary, then express the number as a normalised mantissa times a power of two. Adjust the exponent accordingly and store both in the prescribed bit patterns. For example, convert -6.625 to an 8‑bit mantissa (two’s complement) and 4‑bit exponent (two’s complement) format.
将十进制实数转换为二进制浮点数时,先将整数和小数部分分别转换为二进制,然后将数值表示为规格化尾数与 2 的幂的乘积。相应地调整阶码,并将两者以规定的位模式存储。例如,将 -6.625 转换为 8 位尾数(补码)和 4 位阶码(补码)格式。
Step‑by‑step: 6.625₁₀ = 110.101₂. Normalise: move binary point left 3 places to get 0.110101 × 2³. Since the number is negative, take two’s complement of the mantissa: 0.1101010 → invert → 1.0010101 → add 1 → 1.0010110 (8‑bit). Exponent +3 in 4‑bit two’s complement is 0011. Final representation: 10010110 0011.
逐步来:6.625₁₀ = 110.101₂。规格化:将小数点左移 3 位得到 0.110101 × 2³。由于原数为负,对尾数取补码:0.1101010 → 取反 → 1.0010101 → 加 1 → 1.0010110(8 位)。阶码 +3 用 4 位补码表示为 0011。最终表示:10010110 0011。
To convert back, identify the sign, apply the exponent to determine the binary point, convert the mantissa to decimal, and combine.
反向转换时,先识别符号,应用阶码确定二进制小数点的位置,将尾数转为十进制,然后合并。
11. Precision, Range, and Trade‑offs in Floating Point | 浮点中的精度、范围与权衡
All floating point systems involve trade‑offs between range and precision. A larger exponent field extends the range of representable numbers but reduces the bits available for the mantissa, lowering precision. Conversely, a larger mantissa gives more fractional bits and higher precision but restricts the exponent range.
所有浮点系统都涉及范围与精度之间的权衡。较大的阶码字段可扩展可表示数的范围,但会减少尾数的可用位数,降低精度。相反,较大的尾数能提供更多小数位和更高精度,却会限制阶码的范围。
Rounding errors and truncation are unavoidable when a number cannot be represented exactly with the available mantissa bits. For example, the decimal 0.1 cannot be represented precisely in binary, leading to small errors that can accumulate in iterative calculations. CCEA may ask you to discuss such limitations.
当一个数无法用给定的尾数位精确表示时,舍入误差和截断就不可避免。例如,十进制 0.1 在二进制中无法精确表示,从而产生微小误差,在迭代计算中可能累积。CCEA 考试可能要求你讨论此类局限性。
Understanding these trade‑offs is essential for selecting suitable data representations in programming and for appreciating why real numbers are often approximations in computer systems.
理解这些权衡对于在编程中选择合适的数据表示以及认识为什么实数在计算机系统中往往是近似值至关重要。
12. Fixed Point Representation (Bonus Context) | 定点表示(额外背景)
While floating point dominates general‑purpose computing, fixed point representation is sometimes used in embedded systems or digital signal processing where precision requirements are strict and ranges are known. In fixed point, the binary point is fixed at a predetermined position, so the number of integer bits and fractional bits is constant. This eliminates the need for an exponent, simplifying hardware but severely constraining dynamic range.
尽管浮点数在通用计算中占主导地位,定点表示有时也用于嵌入式系统或数字信号处理,这类场景对精度要求严格且数值范围已知。在定点表示中,二进制小数点固定在预先确定的位置,因此整数位和小数位的数量是固定的。这省去了阶码,简化了硬件,但严重限制了动态范围。
An 8‑bit unsigned fixed point format with 4 integer bits and 4 fractional bits could represent values from 0 to 15.9375 in steps of 0.0625. The conversion process is similar: treat the binary value as an integer and then divide by 2⁴. Fixed point is not a major focus in CCEA A‑Level but provides useful context when comparing representation schemes.
一种 8 位无符号定点格式,如果 4 位整数位和 4 位小数位,可表示的范围是 0 到 15.9375,步长为 0.0625。转换过程相似:将二进制值视为整数,然后除以 2⁴。定点表示并非 CCEA A‑Level 的重点,但在比较各种表示方案时提供了有用的背景知识。
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课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply