📚 IGCSE OCR Computer Science: Binary Mastery Guide | IGCSE OCR 计算机:二进制考点精讲
In the OCR IGCSE Computer Science course, binary is the foundational concept that underpins all data representation and processing. Understanding binary numbers, conversions, arithmetic, and related topics such as hexadecimal and logical shifts is essential for success in the exam. This guide breaks down every key area, providing clear explanations, worked examples, and practical tips to help you master binary with confidence.
在OCR IGCSE计算机科学课程中,二进制是支撑所有数据表示与处理的基础概念。理解二进制数、进制转换、算术运算以及十六进制、逻辑移位等相关主题,对考试成功至关重要。本指南将逐一讲解每个关键领域,提供清晰的解释、实例演示和实用建议,帮助你自信掌握二进制。
1. The Binary Number System | 二进制系统简介
All data in a computer is stored and processed as binary digits, or bits. A bit can only be 0 or 1, representing two states – typically off and on. Groups of bits form larger units; the most common grouping is the byte, which consists of 8 bits. A nibble is half a byte (4 bits). Because computers are built from billions of tiny switches (transistors), the binary system maps perfectly to their physical on/off nature.
计算机中的所有数据都以二进制数字(即比特)的形式存储和处理。一个比特只能是0或1,代表两种状态——通常是关和开。多个比特组成更大的单位;最常见的组合是字节,由8个比特组成。一个半字节是4个比特。由于计算机由数十亿个微型开关(晶体管)构成,二进制系统完美地对应了它们的物理开/关特性。
When we write binary numbers, we usually use the prefix ‘0b’ or show the base as a subscript. For example, 0b1010 or 1010₂ represents the number ten. In the exam, you must be able to read, write, and interpret 8‑bit binary numbers fluently.
表示二进制数时,我们常在前面加“0b”或将基数写作下标。例如,0b1010 或 1010₂ 表示数字十。在考试中,你必须能够熟练地读写和解释8位二进制数。
2. Place Value in Binary | 二进制位值
Just like the denary (base‑10) system uses place values of 1, 10, 100, 1000, the binary system uses powers of two. For an 8‑bit number, the place values from left to right are 128, 64, 32, 16, 8, 4, 2, 1. The leftmost bit is the most significant bit (MSB), and the rightmost is the least significant bit (LSB).
正如十进制系统使用1、10、100、1000作为位值,二进制系统使用2的幂次。对于一个8位数,从左到右的位值依次是128、64、32、16、8、4、2、1。最左边的位称为最高有效位(MSB),最右边的位称为最低有效位(LSB)。
| Bit position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Example: 0 1 0 1 1 0 1 0 | 0 | 1×64 | 0 | 1×16 | 1×8 | 0 | 1×2 | 0 |
The total value is 64 + 16 + 8 + 2 = 90. Always draw the place‑value table when converting to avoid errors. This table is your most reliable tool for both binary‑to‑denary and denary‑to‑binary conversions.
总和为64 + 16 + 8 + 2 = 90。进行转换时,务必画出位值表以避免错误。这张表是你进行二进制转十进制和十进制转二进制最可靠的工具。
3. Converting Binary to Denary | 二进制转十进制
To convert an 8‑bit binary number to denary, write the place values above each bit. Add the place values wherever a 1 appears. For example, convert 10110011₂:
要将一个8位二进制数转换为十进制,请在每个比特上方写出位值。将出现1的位置的对应位值相加。例如,转换10110011₂:
128 + 0 + 32 + 16 + 0 + 0 + 2 + 1 = 179
The binary number 10110011₂ equals 179 in denary. If the binary number has fewer than 8 bits, you can add leading zeros to fill the 8‑bit width. For instance, 1101 becomes 00001101, which is 8 + 4 + 1 = 13.
二进制数10110011₂等于十进制179。如果二进制数不足8位,可以补前导零以填满8位宽度。例如,1101变为00001101,即8 + 4 + 1 = 13。
4. Converting Denary to Binary | 十进制转二进制
The fastest method for the exam is successive division by 2, recording the remainders. Take the denary number 217 and repeatedly divide by 2, writing the remainder each time from bottom to top:
考试中最快的方法是连续除以2,记录余数。以十进制数217为例,不断除以2,每次记录余数,并从下往上读取:
- 217 ÷ 2 = 108 remainder 1
- 108 ÷ 2 = 54 remainder 0
- 54 ÷ 2 = 27 remainder 0
- 27 ÷ 2 = 13 remainder 1
- 13 ÷ 2 = 6 remainder 1
- 6 ÷ 2 = 3 remainder 0
- 3 ÷ 2 = 1 remainder 1
- 1 ÷ 2 = 0 remainder 1
Reading from the last remainder upwards yields 11011001₂. Always check your answer by converting back to denary. For numbers less than 256, an 8‑bit representation is sufficient; if the denary number is larger, you may need more bits.
从最后一个余数向上读取,得到11011001₂。务必通过反向转换来验证你的答案。对于小于256的数字,8位表示就足够了;如果十进制数更大,可能需要更多位。
5. Binary Addition | 二进制加法
Binary addition follows four simple rules: 0+0=0, 0+1=1, 1+0=1, 1+1=0 carry 1. When you add two 8‑bit numbers, work from the LSB to the MSB and carefully manage any carries. Let’s add 01101010₂ (106) and 00111001₂ (57):
二进制加法遵循四条简单规则:0+0=0,0+1=1,1+0=1,1+1=0并进位1。当你将两个8位数相加时,从LSB到MSB逐位计算,并仔细处理进位。我们来计算01101010₂(106)与00111001₂(57)之和:
01101010
+ 00111001
——
10100011
Starting from the right: 0+1=1; 1+0+1 (carry was 0) =0 carry 1; 0+0+1=1; 1+1=0 carry 1; 0+1+1=0 carry 1; 1+1+1=1 carry 1; 1+0+1=0 carry 1; 0+0+1=1. The result is 10100011₂, which is 163 in denary (106+57=163). A fifth rule applies if there is a carry out of the MSB: this is an overflow.
从最右边开始:0+1=1;1+0+1(进位为0)=0 进位1;0+0+1=1;1+1=0 进位1;0+1+1=0 进位1;1+1+1=1 进位1;1+0+1=0 进位1;0+0+1=1。结果为10100011₂,即十进制163(106+57=163)。如果最高有效位有进位输出,这就产生了溢出。
6. Overflow Errors | 溢出错误
An overflow occurs when the result of a binary addition exceeds the maximum value that can be stored in the given number of bits. For 8‑bit unsigned binary, the range is 0 to 255. Adding 11111111₂ (255) and 00000001₂ (1) would require a 9th bit to represent the correct answer 256, but with only 8 bits, the stored result is 00000000₂, and a carry flag is set. This is an overflow error.
当二进制加法的结果超过了给定位数所能存储的最大值时,就会发生溢出。对于8位无符号二进制数,范围是0到255。将11111111₂(255)与00000001₂(1)相加,需要一个第九位来表示正确的答案256,但仅有8位时,存储的结果是00000000₂,并且会设置进位标志。这就是溢出错误。
Computers detect overflow by checking the carry into the MSB and the carry out of the MSB. If they are different, an overflow has occurred. In the IGCSE exam, you may be asked to identify when an overflow happens and explain its consequences, such as incorrect calculation results or program crashes.
计算机通过检查进入MSB的进位和从MSB输出的进位来检测溢出。如果两者不同,就发生了溢出。在IGCSE考试中,你可能需要指出何时发生溢出并解释其后果,例如计算结果错误或程序崩溃。
7. Negative Numbers: Two’s Complement | 负数表示:二进制补码
To represent negative integers, computers use the two’s complement method. In an 8‑bit system, the MSB becomes a sign bit (1 for negative, 0 for positive). The place value of the MSB is –128 instead of +128. The range of an 8‑bit two’s complement number is –128 to +127.
为了表示负整数,计算机使用二进制补码方法。在8位系统中,MSB成为符号位(1表示负,0表示正)。MSB的位值变为–128而不是+128。8位二进制补码数的范围是–128到+127。
To find the two’s complement of a positive number, invert all bits (one’s complement) and then add 1. For example, to represent –27 in 8‑bit two’s complement: start with +27 = 00011011₂. Invert bits → 11100100₂, then add 1 → 11100101₂. This is –27. To convert a two’s complement negative number back to denary, treat the MSB as –128 and add the place values of any remaining 1s. E.g., 11100101₂ = –128 + 64 + 32 + 4 + 1 = –27.
要找到正数的补码,先翻转所有位(反码),然后加1。例如,在8位补码中表示–27:首先+27 = 00011011₂。翻转各位 → 11100100₂,然后加1 → 11100101₂。这就是–27。要将补码负数转回十进制,将MSB视为–128,并加上其余位中所有1的位值。例如,11100101₂ = –128 + 64 + 32 + 4 + 1 = –27。
8. Hexadecimal System | 十六进制系统
Hexadecimal (base‑16) is used to represent binary numbers in a more compact and human‑readable form. It uses digits 0‑9 and letters A‑F (A=10, B=11, C=12, D=13, E=14, F=15). Each hex digit corresponds to exactly one nibble (4 bits). This makes conversion between hex and binary very fast: split the binary number into groups of 4 bits from the right and replace each with its hex equivalent.
十六进制(基数16)用于以更紧凑、更易读的形式表示二进制数。它使用数字0-9和字母A-F(A=10, B=11, C=12, D=13, E=14, F=15)。每个十六进制数字恰好对应一个半字节(4位)。这使得十六进制与二进制之间的转换非常快:将二进制数从右往左每4位一组,并把每一组替换为相应的十六进制数字。
For example, convert 1011 1010₂: 1011₂ = B, 1010₂ = A, so the hex is BA. To convert hex to denary, you can multiply each digit by its place value (16ⁿ). For BA₁₆: B×16¹ + A×16⁰ = 11×16 + 10×1 = 186. The exam may ask you to convert between any of the three number systems: binary, denary, and hex.
例如,转换1011 1010₂:1011₂ = B,1010₂ = A,因此十六进制为BA。要将十六进制转换为十进制,可以将每位数字乘以其位值(16ⁿ)。对于BA₁₆:B×16¹ + A×16⁰ = 11×16 + 10×1 = 186。考试可能会要求你在二进制、十进制和十六进制这三种数制之间进行转换。
9. Binary Shifts (Logical Shifts) | 二进制位移(逻辑移位)
A logical shift moves every bit in a binary number a certain number of places to the left or right. Vacant positions are filled with zeros. A left shift of one place multiplies the number by 2; a right shift of one place divides by 2 (integer division, discarding any remainder). Shifting left by n places multiplies by 2ⁿ, and shifting right by n places divides by 2ⁿ.
逻辑移位将二进制数中的每个位向左或向右移动指定的位数。空出的位置用零填充。左移一位相当于原数乘以2;右移一位相当于除以2(整除,舍弃余数)。左移n位相当于乘以2ⁿ,右移n位相当于除以2ⁿ。
Example: Starting with 00010110₂ (22), a left shift of 2 gives 01011000₂ (88 = 22×4). A right shift of 2 on 00010110₂ gives 00000101₂ (5, since 22÷4 = 5 remainder 2, remainder discarded). Be careful: shifting can cause bits to ‘fall off’ the end – this can lead to loss of data precision or overflow if not monitored.
示例:从00010110₂(22)开始,左移2位得到01011000₂(88 = 22×4)。对00010110₂右移2位得到00000101₂(5,因为22÷4 = 5余2,余数被舍弃)。注意:移位可能使位从末端“丢失”——如果不加监控,这会导致数据精度损失或溢出。
10. Exam Tips and Common Pitfalls | 考试技巧与常见错误
Always show your working, especially when drawing place‑value tables or recording remainders. Even if the final answer is incorrect, method marks can be awarded. Use 8 bits unless told otherwise. When adding binary numbers, write them aligned to the right and work column by column, clearly noting any carries.
一定要展示解题步骤,尤其是在画位值表或记录余数时。即使最终答案错误,也可能获得方法分。除非另有说明,使用8位表示法。在进行二进制加法时,将数字右对齐并逐列计算,清楚地标注进位。
Watch out for the difference between unsigned and two’s complement interpretation. If a question asks you to store a negative denary number in binary, you must use two’s complement. Remember that two’s complement range is asymmetric: there is one more negative value than positive. For a 4‑bit two’s complement, the range is –8 to +7. Never fall into the trap of forgetting the sign bit weight.
注意区分无符号数与补码的解释方式。如果题目要求你用二进制存储一个负数,你必须使用补码。记住补码的范围是不对称的:负数比正数多一个。对于4位补码,范围是–8到+7。绝不要忘记符号位的权重。
A common mistake is misreading binary shifts: left shift multiplies, right shift divides. But division always floors the result (truncates towards zero for positive numbers). For negative two’s complement numbers, a right shift is arithmetic (preserves the sign bit), but IGCSE OCR usually tests logical shifts on positive numbers only. Check your syllabus, but be safe: understand that a logical right shift on a two’s complement negative number can produce an incorrect sign.
一个常见错误是误解二进制移位:左移是乘法,右移是除法。但除法总是向下取整(对于正数,向零截断)。对于补码表示的负数,右移是算术移位(保留符号位),但IGCSE OCR通常只考察正数的逻辑移位。请查阅你的考试大纲,但为安全起见,要理解对补码负数进行逻辑右移可能会产生错误的符号。
Finally, practice conversion between binary, denary, and hex until it feels automatic. Timed past‑paper questions will build your speed and confidence. Remember, binary is the language of the computer – and your language too for this exam.
最后,练习二进制、十进制和十六进制之间的转换,直到你感觉驾轻就熟。限时完成历年真题将提高你的速度和信心。请记住,二进制是计算机的语言——也是你在这场考试中的语言。
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课程辅导,国外大学本科硕士研究生博士课程论文辅导