Binary Essentials for IGCSE WJEC Computer Science | IGCSE WJEC 计算机:二进制 考点精讲

📚 Binary Essentials for IGCSE WJEC Computer Science | IGCSE WJEC 计算机:二进制 考点精讲

Are you preparing for the IGCSE WJEC Computer Science exam? Understanding binary is crucial for scoring top marks in data representation. This revision guide breaks down every key binary topic, from bits and bytes to two’s complement arithmetic, with clear examples and exam-focused tips.

正在备考 IGCSE WJEC 计算机科学吗?二进制是数据表示部分取得高分的关键。这篇复习指南将剖析每一个二进制核心考点,从位与字节到补码运算,配以清晰的示例和应试技巧。


1. Binary Basics: Bits and Bytes | 二进制基础:位与字节

Binary is a base-2 number system that uses only two digits: 0 and 1. Each individual binary digit is called a bit (binary digit). A group of 8 bits is called a byte, which is the fundamental unit of storage in most computers.

二进制是一种基数为2的数字系统,仅使用两个数字:0 和 1。每一个二进制数字称为一个比特(位)。8 个比特组成一个字节,这是大多数计算机的基本存储单位。

Computers use binary because their internal digital circuits have two stable states, easily represented as ON (1) and OFF (0). All types of data – numbers, text, images, sound – are ultimately encoded as sequences of bits.

计算机使用二进制是因为其内部数字电路具有两种稳定状态,可简单地表示为开(1)和关(0)。所有类型的数据——数字、文字、图像、声音——最终都会被编码为比特序列。

Larger groupings of bytes are measured using binary prefixes: 1 kilobyte (KB) is 1024 bytes, 1 megabyte (MB) is 1024 KB, 1 gigabyte (GB) is 1024 MB, and 1 terabyte (TB) is 1024 GB. In exams, be aware that storage sizes are often powers of 2.

更大的字节组合使用二进制前缀来度量:1 千字节 (KB) 是 1024 字节,1 兆字节 (MB) 是 1024 KB,1 吉字节 (GB) 是 1024 MB,1 太字节 (TB) 是 1024 GB。考试中要注意存储容量通常是 2 的幂。


2. Place Values in Binary | 二进制位权值

In binary, just like in decimal, each digit position has a place value. For an 8-bit binary number, the place values from left to right are 2⁷, 2⁶, 2⁵, 2⁴, 2³, 2², 2¹, 2⁰, which correspond to 128, 64, 32, 16, 8, 4, 2, 1.

在二进制中,就像十进制一样,每个数字位置都有一个位权值。对于 8 位二进制数,从左到右的位权值依次为 2⁷、2⁶、2⁵、2⁴、2³、2²、2¹、2⁰,即 128、64、32、16、8、4、2、1。

The leftmost bit is the most significant bit (MSB) as it carries the greatest weight; the rightmost bit is the least significant bit (LSB). Reading a binary number from MSB to LSB, each ‘1’ contributes its place value, and each ‘0’ contributes nothing.

最左边的位是最高有效位 (MSB),因为它具有最大的权重;最右边的位是最低有效位 (LSB)。从 MSB 到 LSB 读二进制数时,每个 ‘1’ 贡献其位权值,每个 ‘0’ 贡献零。

Place value (2n) 128 64 32 16 8 4 2 1
Example bit 1 0 1 0 1 1 0 1

The table above shows how the binary number 10101101₂ can be decoded by summing the place values where a ‘1’ appears: 128 + 32 + 8 + 4 + 1 = 173 in decimal.

上表展示了如何解码二进制数 10101101₂:将出现 ‘1’ 的位权值相加,即 128 + 32 + 8 + 4 + 1 = 173(十进制)。


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

To convert a binary number to decimal, write down the place values from right to left, starting at 1 and doubling each time. For an 8-bit number, the sequence is 128, 64, 32, 16, 8, 4, 2, 1. Write the binary digits underneath, multiply each bit by its place value, and sum all the results.

要将二进制转换为十进制,从右向左写下位权值,从 1 开始,每次加倍。对于 8 位数,序列为 128、64、32、16、8、4、2、1。将二进制数字放在下方,每位乘以其位权值,然后求总和。

Example: Convert 01101001₂ to decimal. The bits align with place values: 0×128, 1×64, 1×32, 0×16, 1×8, 0×4, 0×2, 1×1. Adding the non-zero terms: 64 + 32 + 8 + 1 = 105. So 01101001₂ = 105₁₀.

示例:将 01101001₂ 转换为十进制。比特对齐位权值:0×128、1×64、1×32、0×16、1×8、0×4、0×2、1×1。非零项相加:64 + 32 + 8 + 1 = 105。因此 01101001₂ = 105₁₀。

For an exam, you can quickly sketch a place-value row and tick the ‘1’ positions. Remember that leading zeros do not change the value; they merely ensure we are working with a fixed bit width.

考试时,你可以快速画出一个位权行,并在 ‘1’ 的位置上做标记。请记住,前导零不改变数值;它们只是确保我们使用固定位宽。


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

The most reliable method for converting a decimal integer to binary is successive division by 2. Divide the number by 2, write down the remainder (0 or 1), and repeat with the quotient until the quotient becomes 0. The binary equivalent is formed by reading the remainders from bottom to top.

将十进制整数转换为二进制最可靠的方法是连续除以 2。将数字除以 2,记下余数(0 或 1),再用商重复此过程,直到商为 0。从下往上读取余数即得二进制表示。

Example: Convert 156₁₀ to binary. 156 ÷ 2 = 78 rem 0; 78 ÷ 2 = 39 rem 0; 39 ÷ 2 = 19 rem 1; 19 ÷ 2 = 9 rem 1; 9 ÷ 2 = 4 rem 1; 4 ÷ 2 = 2 rem 0; 2 ÷ 2 = 1 rem 0; 1 ÷ 2 = 0 rem 1. Read remainders upwards: 10011100. So 156₁₀ = 10011100₂ (8 bits).

示例:将 156₁₀ 转换为二进制。156 ÷ 2 = 78 余 0;78 ÷ 2 = 39 余 0;39 ÷ 2 = 19 余 1;19 ÷ 2 = 9 余 1;9 ÷ 2 = 4 余 1;4 ÷ 2 = 2 余 0;2 ÷ 2 = 1 余 0;1 ÷ 2 = 0 余 1。向上读取余数:10011100。所以 156₁₀ = 10011100₂(8 位)。

If the binary result is shorter than the required bit width, pad with leading zeros on the left. For instance, 13₁₀ becomes 1101₂, which in 8-bit representation is 00001101.

如果二进制结果短于所需位宽,则在左侧填充前导零。例如,13₁₀ 变为 1101₂,8 位表示则为 00001101。


5. Binary Addition | 二进制加法

Binary addition follows similar rules to decimal addition but with only four basic sums: 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, and 1 + 1 = 0 with a carry of 1 to the next column. When three 1s are added (1+1+1), the result is 1 with a carry of 1.

二进制加法遵循与十进制类似的规则,但只有四种基本求和:0 + 0 = 0、0 + 1 = 1、1 + 0 = 1、1 + 1 = 0 并向下一列进位 1。当三个 1 相加(1+1+1)时,结果为 1 并进位 1。

Let’s add the 8-bit numbers 00101010 and 00001111. Work column by column from the LSB: 0+1=1, 1+1=0 carry 1, 0+1+carry1=0 carry 1, 1+1+carry1=1 carry 1, 0+0+carry1=1, 1+0=1, 0+0=0, 0+0=0. The result is 00111001₂, which is 57₁₀. Indeed 42 + 15 = 57.

我们来计算 8 位数 00101010 和 00001111 的加法。从 LSB 开始逐列计算:0+1=1,1+1=0 进位1,0+1+进位1=0 进位1,1+1+进位1=1 进位1,0+0+进位1=1,1+0=1,0+0=0,0+0=0。结果为 00111001₂,即 57₁₀。确实 42 + 15 = 57。

In the IGCSE exam, you may be asked to show the carry row separately. Always align the numbers by their LSBs and clearly indicate any carries.

在 IGCSE 考试中,你可能会被要求单独写出进位行。始终按 LSB 对齐数字,并清晰地标出所有进位。


6. Overflow Errors | 溢出错误

Overflow occurs when the result of a binary addition exceeds the maximum value that can be stored in the allocated number of bits. In an 8-bit register, the maximum unsigned value is 255 (11111111₂). If an addition produces a 9th bit, this carry out of the MSB is lost, causing an incorrect result.

当二进制加法结果超过了给定位数所能存储的最大值时,就会发生溢出。在 8 位寄存器中,最大无符号值为 255(11111111₂)。如果加法产生了一个第 9 位,这个超出 MSB 的进位就会丢失,导致结果错误。

Example: 11111111₂ (255) + 00000001₂ (1). Adding gives 1 00000000₂. The leftmost ‘1’ is a carry out of the 8-bit space, leaving 00000000₂, which is 0 instead of 256. This is an overflow error.

示例:11111111₂ (255) + 00000001₂ (1)。相加得到 1 00000000₂。最左边的 ‘1’ 是超出 8 位空间的进位,剩下 00000000₂,即 0 而不是 256。这就是溢出错误。

Computers detect overflow using status flags. In two’s complement signed arithmetic, overflow is indicated when adding two positive numbers yields a negative result, or adding two negatives yields a positive.

计算机使用状态标志来检测溢出。在二进制补码有符号运算中,当两个正数相加得到负数,或两个负数相加得到正数时,表明发生了溢出。


7. Binary Shifts (Logical Shifts) | 二进制移位(逻辑移位)

A logical shift moves all bits in a register to the left or right by a specified number of positions. Vacant positions are filled with zeros, and bits shifted beyond the boundary are discarded.

逻辑移位将寄存器中的所有位向左或向右移动指定的位数。空出的位置用零填充,移出边界的位被丢弃。

A left logical shift of one place multiplies the number by 2. For example, 00101100₂ (44₁₀) left-shifted gives 01011000₂ (88₁₀). A left shift of n places is equivalent to multiplying by 2ⁿ.

逻辑左移一位相当于将数值乘以 2。例如,00101100₂ (44₁₀) 左移一位得到 01011000₂ (88₁₀)。左移 n 位等同于乘以 2ⁿ。

A right logical shift divides the number by 2, ignoring any remainder. 01011000₂ (88) right-shifted once becomes 00101100₂ (44). Be careful: shifting a ‘1’ out of the LSB discards it, which is integer division.

逻辑右移将数值除以 2,忽略余数。01011000₂ (88) 右移一位变为 00101100₂ (44)。注意:从 LSB 移出 ‘1’ 会将其丢弃,这就是整数除法。

Shifts are used for fast multiplication and division by powers of two, but an incorrect shift can cause data loss. WJEC questions often ask you to perform a shift and interpret the result in decimal.

移位用于快速的 2 的幂乘除运算,但错误的移位会导致数据丢失。WJEC 考题常要求你执行移位并以十进制解释结果。


8. Representing Negative Numbers: Sign-Magnitude and Two’s Complement | 负数表示:符号-幅值与二进制补码

Two methods are used to represent signed integers in binary: sign-magnitude and two’s complement. In sign-magnitude, the MSB acts as the sign bit (0 for positive, 1 for negative), and the remaining bits store the magnitude.

有两种方法用于在二进制中表示有符号整数:符号-幅值和二进制补码。在符号-幅值表示法中,MSB 作为符号位(0 为正,1 为负),其余位存储数值的大小。

For 8 bits, +18 is 00010010, and -18 is 10010010. Sign-magnitude has two zeros (00000000 and 10000000), which complicates arithmetic. It is rarely used in modern computers for integer arithmetic.

对于 8 位,+18 是 00010010,-18 是 10010010。符号-幅值存在两个零(00000000 和 10000000),这使运算变得复杂。现代计算机中很少用它进行整数运算。

Two’s complement is the standard method. A negative number is formed by inverting all bits of its positive counterpart (one’s complement) and adding 1. For -18: +18 = 00010010 → invert to 11101101 → add 1 → 11101110. This resolves the double-zero problem and simplifies subtraction.

二进制补码是标准方法。一个负数由其相应正数所有位取反(反码)后加 1 形成。以 -18 为例:+18 = 00010010 → 取反得 11101101 → 加 1 → 11101110。这解决了双零问题,并简化了减法。

In two’s complement, the MSB still indicates sign, but the place value of the MSB is -128 (for 8 bits). The range for 8-bit two’s complement is -128 to +127.

在补码中,MSB 依然表示符号,但其位权值是 -128(对于 8 位)。8 位补码的范围是 -128 到 +127。


9. Two’s Complement Conversion and Arithmetic | 补码转换与运算

To convert a negative decimal number to 8-bit two’s complement: ignore the sign and convert the magnitude to binary, pad to 8 bits, flip all bits, then add 1. For -43: 43 = 00101011 → flip 11010100 → add 1 = 11010101.

要将负十进制数转换为 8 位补码:忽略符号,将数值转换为二进制,填充至 8 位,所有位取反,然后加 1。对于 -43:43 = 00101011 → 取反 11010100 → 加 1 = 11010101。

To convert a two’s complement number back to decimal: if MSB is 0, it is positive and can be read normally; if MSB is 1, it is negative. Compute its magnitude by flipping all bits and adding 1, then apply the minus sign. E.g., 11101110 → flip 00010001 → +1 = 00010010 (18) → -18.

将补码数转换回十进制:如果 MSB 是 0,则为正数,可直接读取;如果 MSB 是 1,则为负数。通过所有位取反再加 1 计算其数值,然后加上负号。例如,11101110 → 取反 00010001 → +1 = 00010010 (18) → -18。

Two’s complement addition is identical to unsigned binary addition; you simply add the bit patterns and discard any carry beyond the fixed width. The result is automatically correct if within range.

补码加法与无符号二进制加法完全相同;你只需将位模式相加,并丢弃超出固定宽度的任何进位。如果结果在范围内,会自动得到正确值。


10. Binary Subtraction using Two’s Complement | 使用补码进行二进制减法

Instead of building a subtraction circuit, computers perform subtraction by adding the two’s complement of the number being subtracted. That is, A − B = A + (−B).

计算机并不构建减法电路,而是通过加上被减数的补码来执行减法。即 A − B = A + (−B)。

Example: 7 − 3 in 8-bit. Represent 7 as 00000111. Represent −3 by taking 3 (00000011), flipping to 11111100, adding 1 to get 11111101. Add: 00000111 + 11111101 = 1 00000100. Ignore the carry-out, leaving 00000100₂ = 4₁₀.

示例:8 位下 7 − 3。将 7 表示为 00000111。取 3 (00000011),取反得 11111100,加 1 得 11111101 表示 −3。相加:00000111 + 11111101 = 1 00000100。舍弃进位,剩下 00000100₂ = 4₁₀。

Always check that both operands are in the same bit width and that the result does not overflow. In two’s complement subtraction, overflow occurs if the sign of the result is inconsistent with the expected sign based on the operands.

务必检查两个操作数具有相同的位宽,且结果不溢出。在补码减法中,如果结果的符号与根据操作数预期的符号不一致,则发生溢出。


11. Binary and Hexadecimal Conversion | 二进制与十六进制转换

Hexadecimal (base-16) is a compact way to represent binary data. Since 16 = 2⁴, each hex digit corresponds exactly to a group of 4 bits (a nibble). This makes conversions very straightforward.

十六进制(基数为16)是表示二进制数据的紧凑方式。因为 16 = 2⁴,每一个十六进制数字恰好对应一组 4 位(一个半字节)。这使得转换变得非常简单。

Binary Hex
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 APublished by TutorHao | IGCSE 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