A-Level WJEC Computer Science: Binary Essentials | A-Level WJEC 计算机科学:二进制 考点精讲

📚 A-Level WJEC Computer Science: Binary Essentials | A-Level WJEC 计算机科学:二进制 考点精讲

Understanding binary is fundamental to computer science, as all data and instructions inside a computer are ultimately represented using 0s and 1s. This guide covers the key binary concepts examined in the WJEC A-Level specification, including number conversions, binary arithmetic, two’s complement representation, bit shifts, and hexadecimal shorthand. Mastery of these topics will build a solid foundation for tackling data representation, processor operations, and more advanced digital logic.

理解二进制是计算机科学的基础,因为计算机内部的所有数据和指令最终都用 0 和 1 表示。本指南涵盖了 WJEC A-Level 考纲中的核心二进制考点,包括进制转换、二进制算术、补码表示、位移以及十六进制简写。掌握这些主题将为数据表示、处理器操作以及更高级的数字逻辑打下坚实基础。


1. The Binary Number System and its Importance | 二进制数系及其重要性

Computers use the binary number system because electronic components naturally represent two stable states, typically on (1) and off (0). A single binary digit is called a bit. Eight bits form a byte, which is the smallest addressable unit of memory in most architectures. Larger groupings, such as 16-bit words or 32-bit double words, are common. Understanding the place values is key: in an n-bit binary number, the rightmost bit has weight 2⁰, the next 2¹, then 2², …, up to 2ⁿ⁻¹ on the left.

计算机使用二进制数系是因为电子元件天然地表示两种稳定状态,通常是开(1)和关(0)。一个二进制位称为一个比特。八个比特构成一个字节,字节是大多数体系结构中内存的最小可寻址单位。更大的分组,如 16 位的字或 32 位的双字也很常见。理解位权是关键:在一个 n 位二进制数中,最右边的位权为 2⁰,下一位为 2¹,然后是 2²,……,最左边为 2ⁿ⁻¹。

Exam questions often ask you to state the range of unsigned numbers that can be stored in a given number of bits. For n bits, the smallest is 0 and the largest is 2ⁿ − 1. For example, with 8 bits, the range is 0 to 255 (2⁸ − 1). This is pure binary (unsigned) representation.

考题常会要求你写出给定位数能存储的无符号数范围。对于 n 个比特,最小值为 0,最大值为 2ⁿ − 1。例如,8 个比特的范围是 0 到 255(2⁸ − 1)。这就是纯二进制(无符号)表示法。


2. Converting Binary to Decimal | 二进制转十进制

To convert an unsigned binary number to denary (decimal), sum the place values where the bit is 1. Write the binary digits above their corresponding powers of two, then add the contributions. Example: 101101₂ → 1×2⁵ + 0×2⁴ + 1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 32 + 8 + 4 + 1 = 45₁₀. This method works for any length binary string. In WJEC exams, you may be asked to show your working clearly.

要将无符号二进制数转换为十进制,只需将位值为 1 的位权相加。将二进制位写在其对应的 2 的幂之上,然后累加。示例:101101₂ → 1×2⁵ + 0×2⁴ + 1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 32 + 8 + 4 + 1 = 45₁₀。该方法适用于任意长度的二进制串。在 WJEC 考试中,可能会要求你清晰地展示过程。

Quick check: the binary number 10000000₂ as unsigned has value 2⁷ = 128₁₀. 11111111₂ = 255₁₀. Knowing common patterns and powers of two speeds up calculations.

快速检查:无符号二进制数 10000000₂ 的值为 2⁷ = 128₁₀。11111111₂ = 255₁₀。熟悉常见模式及二的幂次可以加快计算速度。


3. Converting Decimal to Binary | 十进制转二进制

The standard method for converting a positive decimal integer to binary is successive division by 2. Repeatedly divide the decimal number by 2, recording the remainder each time. Read the remainders from bottom to top to obtain the binary equivalent. Example: convert 57₁₀ to binary:

将正整数十进制转换为二进制的标准方法是连续除以 2 取余法。不断将十进制数除以 2,记录每次的余数。从下往上读取余数即可得到二进制数。示例:将 57₁₀ 转换为二进制:

Division Quotient Remainder
57 ÷ 2 28 1 (LSB)
28 ÷ 2 14 0
14 ÷ 2 7 0
7 ÷ 2 3 1
3 ÷ 2 1 1
1 ÷ 2 0 1 (MSB)

Reading remainders upwards: 111001. Thus 57₁₀ = 111001₂. An alternative method is to subtract the largest power of two that fits, set that bit to 1, and continue. Both methods are acceptable, but the division method is systematic and less error-prone when the number of bits is fixed.

从下往上读取余数:111001。因此 57₁₀ = 111001₂。另一种方法是减去能容纳的最大 2 的幂,将该位置 1,然后继续。两种方法均可接受,但除法更加系统,在位数固定时不易出错。


4. Binary Addition and the Carry | 二进制加法与进位

Binary addition follows simple rules: 0+0=0, 0+1=1, 1+0=1, 1+1=0 carry 1. When adding two n-bit numbers, you may end up with an extra carry out of the most significant bit (MSB). This is the carry flag. In unsigned arithmetic, a carry out of the MSB indicates an overflow: the result exceeds the maximum representable value (2ⁿ − 1). For example, adding 10000000₂ (128) and 10000000₂ (128) gives 1 00000000₂ with a carry out, indicating overflow since 256 > 255.

二进制加法的规则很简单:0+0=0,0+1=1,1+0=1,1+1=0 并进位 1。将两个 n 位二进制数相加时,可能在最高位之外生成一个额外的进位。这就是进位标志。在无符号算术中,最高位外的进位指示溢出:结果超出了可表示的最大值(2ⁿ − 1)。例如,10000000₂(128)加 10000000₂(128)得到 1 00000000₂,并产生进位,表示溢出,因为 256 > 255。

In the WJEC specification, you should be able to perform binary addition column-wise, recording carries. Remember that the carry flag is set only when there is a carry out of the MSB in unsigned operations. For two’s complement (signed) numbers, overflow is detected differently (see section 6).

在 WJEC 考纲中,你应该能够按列进行二进制加法,并记录进位。请记住,进位标志仅当无符号运算中最高位之外产生进位时才置位。对于补码(有符号)数,溢出检测方式不同(见第 6 节)。


5. Representing Negative Numbers with Two’s Complement | 用补码表示负数

In A-Level Computer Science, negative integers are represented using two’s complement. For an n-bit two’s complement number, the MSB has negative weight: −2ⁿ⁻¹. All other bits have their usual positive weights. For example, in 8-bit two’s complement, the MSB represents −128. The value is calculated as: (−bₙ₋₁ × 2ⁿ⁻¹) + Σᵢ₌₀ₙ₋₂ bᵢ × 2ⁱ. Therefore, 10000000₂ = −128 + 0 = −128₁₀, and 11111111₂ = −128 + 127 = −1₁₀.

在 A-Level 计算机科学中,负整数使用补码表示。对于一个 n 位的补码数,最高位具有负位权:−2ⁿ⁻¹。其余位保持通常的正位权。例如,在 8 位补码中,最高位表示 −128。其值计算为:(−bₙ₋₁ × 2ⁿ⁻¹) + Σᵢ₌₀ₙ₋₂ bᵢ × 2ⁱ。因此,10000000₂ = −128 + 0 = −128₁₀,而 11111111₂ = −128 + 127 = −1₁₀。

To find the two’s complement of a number (i.e., negate it), invert all bits (one’s complement) and add 1. Example: to represent −5 in 8-bit two’s complement, start with +5 = 00000101. Invert: 11111010. Add 1: 11111011, which is −5. This method works for both directions: converting a negative two’s complement number back to positive decimal can be done by the same ‘flip and add 1’ technique, then interpreting the result as positive.

要得到一个数的补码(即取负),将所有比特取反(反码)再加 1。示例:用 8 位补码表示 −5,从 +5 = 00000101 开始。取反:11111010。加 1:11111011,这就是 −5。该方法双向适用:将负的补码数转换回正的十进制,同样可以使用“取反加 1”的技巧,然后将结果解释为正数。

The range of an n-bit two’s complement number is from −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1. For 8 bits, −128 to +127. For 16 bits, −32768 to +32767. Questions often ask you to state the range or identify the most negative number.

n 位补码数的范围是从 −2ⁿ⁻¹ 到 2ⁿ⁻¹ − 1。对于 8 位,−128 到 +127。16 位则是 −32768 到 +32767。题目经常要求你说明范围或识别最小的负数。


6. Two’s Complement Addition and Overflow Detection | 补码加法与溢出检测

Adding two two’s complement numbers uses exactly the same binary addition rules, but the interpretation of overflow is different. In signed arithmetic, overflow occurs when the two operands have the same sign but the result has a different sign. For example, adding two positive numbers should give a positive result; if the MSB of the result becomes 1 (negative), overflow has occurred. Similarly, adding two negative numbers and obtaining a positive MSB indicates overflow.

两个补码数相加采用完全相同的二进制加法规则,但对溢出的解释不同。在有符号算术中,溢出发生在两个操作数符号相同但结果的符号却不同的情况。例如,两个正数相加应得到正结果;如果结果的最高位变成了 1(负数),则表示发生了溢出。类似地,两个负数相加却得到正的 MSB 也指示溢出。

Formally, overflow in two’s complement can be detected by checking the carry into the MSB and the carry out of the MSB: if they are different, overflow occurs. This is often implemented in processors with an overflow flag (V flag). You may be required to perform addition and state whether overflow is present, along with a justification.

从形式上看,补码中的溢出可以通过检查进入 MSB 的进位和 MSB 向外的进位来检测:如果两者不同,则发生溢出。处理器中通常用溢出标志(V 标志)来实现。你可能需要执行加法并说明是否发生溢出,并给出理由。

Example: 8-bit two’s complement: 01111111 (+127) + 00000001 (+1) = 10000000 (−128). Here, two positives produced a negative; the result is incorrect and overflow flag would be set. The correct sum, +128, is outside the representable range.

示例:8 位补码:01111111 (+127) + 00000001 (+1) = 10000000 (−128)。此时两个正数相加得到负数;结果错误,溢出标志将被置位。正确的和 +128 已超出可表示范围。


7. Subtraction using Two’s Complement | 利用补码实现减法

In binary systems, subtraction is normally performed by adding the negative of the subtrahend. That is, A − B = A + (−B). First, negate B (flip bits, add 1) to get its two’s complement, then add it to A. Ignore any carry out of the MSB for the final result’s size, but do consider it for overflow detection. This technique allows the arithmetic logic unit (ALU) to use the same adder circuit for both addition and subtraction, saving hardware.

在二进制系统中,减法通常通过加上减数的负数来实现。即 A − B = A + (−B)。首先对 B 取负(位取反再加 1)得到其补码,然后与 A 相加。忽略最终结果超出 MSB 的进位,但要用它来检测溢出。这种方法使得算术逻辑单元(ALU)能够用同一加法器电路完成加法和减法,从而节省硬件。

Example: compute 5 − 3 in 4-bit two’s complement. 5 is 0101, 3 is 0011. Negate 3: 1100 + 1 = 1101. Add: 0101 + 1101 = 1 0010. Discard extra carry, result is 0010₂ = 2, correct. No overflow because the operands have different signs. Questions often ask you to perform subtraction using this method, stating the result and whether overflow occurs.

示例:用 4 位补码计算 5 − 3。5 是 0101,3 是 0011。求 −3:1100 + 1 = 1101。相加:0101 + 1101 = 1 0010。丢弃额外进位,结果为 0010₂ = 2,正确。没有溢出,因为两个操作数符号不同。题目常要求你用此方法执行减法,说明结果以及是否发生溢出。


8. Logical and Arithmetic Bit Shifts | 逻辑位移与算术位移

Shift operations move all bits in a binary word to the left or right. Two types are relevant at A-Level: logical shifts and arithmetic shifts. A logical shift left (LSL) moves every bit one place left; the LSB becomes 0, and the MSB is shifted out, often into the carry flag. A logical shift right (LSR) moves bits right, inserting a 0 at the MSB, with the LSB falling into the carry flag.

移位操作将二进制字中的所有位向左或向右移动。与 A-Level 相关的有两种类型:逻辑位移和算术位移。逻辑左移(LSL)将每一位向左移动一位;最低位填入 0,最高位移出并通常进入进位标志。逻辑右移(LSR)将位向右移动,最高位插入 0,最低位移入进位标志。

Arithmetic shift right (ASR) preserves the sign of a two’s complement number. It shifts bits to the right but the MSB (sign bit) is replicated into the vacant position to its right. This effectively divides the number by 2, rounding down towards negative infinity. Arithmetic shift left is the same as logical shift left; there is no separate ASL because sign is not preserved when shifting left (overflow possible).

算术右移(ASR)保留补码数的符号。它将位向右移动,但 MSB(符号位)会复制到其右侧的空位。这实际上是将数除以 2,并向负无穷方向向下取整。算术左移与逻辑左移相同;没有单独的 ASL,因为左移时不保留符号(可能溢出)。

Example: 8-bit two’s complement −8 is 11111000. ASR one place: 11111100 = −4. LSR one place on the same bit pattern would give 01111100 = +124, destroying the sign. So ASR must be used for signed integer division by powers of two. In WJEC questions, you may be given a bit pattern and asked to apply a shift, interpreting the result both unsigned and signed.

示例:8 位补码 −8 为 11111000。ASR 一位:11111100 = −4。同一位模式下的 LSR 会得到 01111100 = +124,破坏了符号。因此,用 2 的幂次做有符号整数除法时必须使用 ASR。在 WJEC 题目中,可能会给你一个位模式并要求应用移位,然后分别以无符号和有符号方式解释结果。


9. Hexadecimal as a Convenient Shorthand | 十六进制作为方便的简写

Because binary strings can be very long, programmers often use hexadecimal (base 16) to represent binary values compactly. Each hexadecimal digit corresponds exactly to 4 bits (a nibble). Digits 0-9 represent themselves; A–F represent 10–15. Example: binary 1101 0110 is D6₁₆ (D = 13, 6 = 6). Conversion between binary and hex is straightforward: group bits into nibbles from the right, then replace each group with the hex digit.

由于二进制串可能非常长,程序员常使用十六进制(基数为 16)来紧凑地表示二进制值。每一位十六进制数字恰好对应 4 个比特(一个半字节)。数字 0-9 表示自身;A–F 表示 10–15。示例:二进制 1101 0110 就是 D6₁₆(D = 13,6 = 6)。二进制与十六进制之间的转换很简单:从右端开始将比特分为半字节组,然后将每组替换为对应的十六进制数字。

Hexadecimal is heavily used in memory dumps, colour codes (e.g., #FF00A4), assembly language, and debugging. In the WJEC exam, you may be asked to convert between binary, denary, and hexadecimal, or to show the hex representation of a given memory address or data word. Always ensure nibbles are grouped properly; add leading zeros if needed to make complete groups of four.

十六进制在内存转储、颜色代码(如 #FF00A4)、汇编语言和调试中广泛使用。在 WJEC 考试中,你可能会被要求进行二进制、十进制和十六进制之间的转换,或者写出给定内存地址或数据字的十六进制表示。务必确保半字节分组正确;必要时添加前导零以构成完整的四位组。


10. Data Representation Contexts and Word Lengths | 数据表示上下文与字长

The interpretation of a bit pattern depends entirely on the context. The same binary 10000001 could represent 129 as unsigned, −127 in two’s complement, or even an ASCII character (e.g., ‘ü’ in extended ASCII). In WJEC questions, you must always clarify whether a number is unsigned or two’s complement, and whether a shift is logical or arithmetic. Also, word size matters: storing a 16-bit number in an 8-bit register will truncate the most significant bits, potentially altering the value and causing overflow.

位模式的解释完全取决于上下文。同一二进制 10000001 可以表示无符号数 129,补码中的 −127,甚至一个 ASCII 字符(例如扩展 ASCII 中的 ‘ü’)。在 WJEC 题目中,你必须始终说明数字是无符号的还是补码,以及移位是逻辑移位还是算术移位。此外,字长很重要:将 16 位数存储到 8 位寄存器中会截断最高有效位,可能改变数值并导致溢出。

Understanding fixed-point representation for fractions may also be examined; the binary point is placed at a fixed position, with bits after the point representing negative powers of two (½, ¼, etc.). However, two’s complement remains the core topic for integer arithmetic. Keep practicing conversions and arithmetic under timed conditions to build speed and accuracy.

小数的定点表示也可能考查;二进制小数点置于固定位置,小数点后的位表示 2 的负幂(½、¼ 等)。然而,补码仍然是整数算术的核心主题。在限时条件下坚持练习转换和算术,以提高速度和准确度。


11. Common Mistakes and How to Avoid Them | 常见错误及避免方法

Many students lose marks through careless errors. Watch out for: forgetting to include all required bits when converting (e.g., writing 101 for 5 in an 8-bit context should be 00000101); misinterpreting the most significant bit – is it signed or unsigned?; confusing logical and arithmetic right shifts; failing to detect overflow by checking sign changes in signed addition; not showing carry bits clearly in addition working. Always double-check the range of a two’s complement number before declaring an answer valid.

许多学生因粗心而失分。要注意:转换时忘记包括所有要求的位数(例如,在 8 位上下文中,5 写成 101 应为 00000101);误解最高位——是有符号还是无符号?;混淆逻辑右移和算术右移;未能通过检查有符号加法中的符号变化来检测溢出;加法过程中未清晰地展示进位。在声明答案有效之前,务必再次检查补码数的范围。

Another typical pitfall is adding binary numbers without aligning columns correctly under the place values. Use grid paper or draw vertical lines during exam practice. Also, when negating a two’s complement number, some students forget the final ‘add 1’ step. Remember the rhyme: “flip the bits, then add one, the negative has begun.”

另一个典型陷阱是在位权下对齐列时不仔细。练习时使用方格纸或画竖线。此外,在求补码负数时,有些同学会忘记最后的“加 1”步骤。记住口诀:“取反再加一,负数已完毕。”


12. Exam-Style Question Walkthrough | 考试风格题目演练

Consider this WJEC-style question: “Using 8-bit two’s complement, perform 45 − 73. Show your working and state whether overflow occurs.” First, convert both to binary: 45 = 00101101, 73 = 01001001. Negate 73: invert to 10110110, add 1 ⇒ 10110111 (−73). Add: 00101101 + 10110111 = 11100100. MSB is 1, result is negative. To interpret, take two’s complement of result: invert 00011011 + 1 = 00011100 = 28, so result is −28. Check: 45 − 73 = −28, correct. Signs: operands have different signs, so overflow cannot occur; no overflow. This demonstrates clear working, correct binary addition, and correct signed interpretation.

看一道 WJEC 风格题目:“使用 8 位补码,计算 45 − 73。展示计算过程并说明是否发生溢出。”首先将两者转换为二进制:45 = 00101101,73 = 01001001。对 73 取负:取反得 10110110,加 1 ⇒ 10110111 (−73)。相加:00101101 + 10110111 = 11100100。MSB 为 1,结果负数。解释时,对结果求补码:取反 00011011 + 1 = 00011100 = 28,因此结果为 −28。验算:45 − 73 = −28,正确。符号:两个操作数符号不同,因此不可能溢出;无溢出。这下展示了清晰的运算过程、正确的二进制加法以及正确的有符号解释。

For high marks, always state the final answer in both binary and denary, comment on overflow/carry flags, and show any working with carries. If the question asks for hexadecimal, convert the final binary answer to hex by splitting into nibbles: 1110 0100 = E4₁₆. Demonstrating cross-checks where appropriate can also earn credit.

要获得高分,一定要用二进制和十进制两种形式写出最终答案,评论溢出/进位标志,并展示进位过程。如果题目要求十六进制,则将最终二进制答案拆分为半字节:1110 0100 = E4₁₆。在适当处展示交叉检查也能得分。

Published by TutorHao | WJEC 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课程辅导,国外大学本科硕士研究生博士课程论文辅导

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