📚 IB & WJEC Computer Science: Binary Numbers Key Points | IB与WJEC计算机:二进制考点精讲
Binary is the fundamental language of computers, representing all data and instructions as sequences of 0s and 1s. This article covers essential binary concepts for IB and WJEC Computer Science, including number base conversions, arithmetic, two’s complement, bit shifts, character encoding, and representation of multimedia. Each section pairs clear English explanations with Chinese translations to support bilingual learners.
二进制是计算机的基本语言,所有数据和指令都以 0 和 1 的序列表示。本文涵盖 IB 和 WJEC 计算机科学中二进制的重要考点,包括数制转换、算术运算、补码、位移动、字符编码以及多媒体表示。每个部分将清晰的英文解释与中文翻译配对,以支持双语学习者。
1. Number Bases and Place Value | 数制与位值
Computers use the binary (base-2) system because digital circuits recognise only two states: on (1) and off (0). In any number system, each digit has a place value determined by the base raised to a power. For binary, place values from right to left are 2&sup0;, 2¹, 2², 2³, and so on. The decimal system (base-10) uses powers of 10. Understanding place value is the foundation for all conversions and arithmetic.
计算机使用二进制(基数为 2)系统,因为数字电路只能识别两种状态:开(1)和关(0)。在任何数制中,每个数字都有一个由基数的幂决定的位值。对于二进制,从右到左的位值分别是 2&sup0;、2¹、2²、2³ 等。十进制(基数为 10)使用 10 的幂。理解位值是所有转换和算术运算的基础。
For example, the binary number 11012 is interpreted as (1 × 2³) + (1 × 2²) + (0 × 2¹) + (1 × 2&sup0;). In exams, you are often required to label the place values above each bit to avoid mistakes.
例如,二进制数 11012 应理解为 (1 × 2³) + (1 × 2²) + (0 × 2¹) + (1 × 2&sup0;)。在考试中,通常需要在每位上方标注位值以避免出错。
2. Binary to Decimal Conversion | 二进制转十进制
To convert a binary number to decimal, multiply each bit by its place value and sum the results. Work from right to left, starting with 2&sup0; = 1. For 8-bit numbers, the place values are 128, 64, 32, 16, 8, 4, 2, 1. The sum gives the decimal equivalent.
要将二进制数转换为十进制,需将每一位乘以其位值,然后求和。从右向左进行,起始位值为 2&sup0; = 1。对于 8 位二进制数,位值依次为 128、64、32、16、8、4、2、1。求和后得到对应的十进制数。
Example: Convert 010101102 to decimal. Starting from the leftmost bit (128), we have 0×128 + 1×64 + 0×32 + 1×16 + 0×8 + 1×4 + 1×2 + 0×1 = 64 + 16 + 4 + 2 = 8610. Always double-check your addition.
示例:将 010101102 转换为十进制。从最左边的位(128)开始,计算得到 0×128 + 1×64 + 0×32 + 1×16 + 0×8 + 1×4 + 1×2 + 0×1 = 64 + 16 + 4 + 2 = 8610。务必仔细检查加法。
3. Decimal to Binary Conversion | 十进制转二进制
Two common methods convert decimal numbers to binary: the division-by-2 method and the subtraction-of-powers method. The division method repeatedly divides the decimal number by 2, recording the remainder at each step. The remainders read from bottom to top give the binary equivalent.
十进制转二进制有两种常用方法:除 2 取余法和幂减法。除 2 取余法将十进制数反复除以 2,记录每一步的余数。从下往上读取余数,即得到二进制结果。
Using the division method for 5310: 53 ÷ 2 = 26 r 1; 26 ÷ 2 = 13 r 0; 13 ÷ 2 = 6 r 1; 6 ÷ 2 = 3 r 0; 3 ÷ 2 = 1 r 1; 1 ÷ 2 = 0 r 1. Reading upwards gives 1101012. For an 8-bit representation, add leading zeros: 001101012.
以 5310 使用除 2 取余法为例:53 ÷ 2 = 26 余 1;26 ÷ 2 = 13 余 0;13 ÷ 2 = 6 余 1;6 ÷ 2 = 3 余 0;3 ÷ 2 = 1 余 1;1 ÷ 2 = 0 余 1。向上读取得到 1101012。若要表示 8 位二进制,则需在高位补零:001101012。
The subtraction method works well for smaller numbers: subtract the largest power of 2 that fits, write 1 in that position, then repeat with the remainder. Both methods are accepted in exams.
幂减法对于较小的数更便捷:减去所能容纳的最大的 2 的幂,在该位写 1,然后对余数重复操作。两种方法考试均接受。
4. Hexadecimal System (Base-16) | 十六进制(基数为 16)
Hexadecimal uses sixteen symbols: 0-9 and A-F (A=10, B=11, C=12, D=13, E=14, F=15). It is widely used in computing because one hex digit maps exactly to four binary bits (a nibble). This makes it much shorter and less error-prone when representing large binary values, such as memory addresses or color codes.
十六进制采用十六个符号:0–9 和 A–F(A=10, B=11, C=12, D=13, E=14, F=15)。它在计算中广泛使用,因为一个十六进制位恰好对应四位二进制(一个半字节)。这使得在表示内存地址或颜色代码等大型二进制值时更加简短且不易出错。
To convert binary to hex, group the bits into sets of four from the right, then replace each group with its hex equivalent. The binary 110110112 becomes 1101 1011, which is D B in hex, so DB16 or 0xDB.
二进制转十六进制时,从右按四位一组划分,然后将每组替换为对应的十六进制符号。二进制 110110112 可划分为 1101 和 1011,分别是 D 和 B,因此得到 DB16 或写作 0xDB。
Decimal to hex conversion can be done by repeated division by 16, recording remainders in the range 0-15 and converting digits above 9 to letters.
十进制转十六进制可以通过反复除以 16 并记录 0–15 范围内的余数,再将大于 9 的数字转换为字母完成。
| Decimal | Binary (4-bit) | Hex |
| 0 | 0000 | 0 |
| 5 | 0101 | 5 |
| 10 | 1010 | A |
| 15 | 1111 | F |
5. Binary Arithmetic: Addition and Overflow | 二进制算术:加法与溢出
Binary addition follows rules similar to decimal addition: 0+0=0, 0+1=1, 1+0=1, 1+1=0 with a carry of 1 to the next column. When adding two binary numbers, align them by their least significant bits and work from right to left.
二进制加法遵循与十进制相似的规则:0+0=0,0+1=1,1+0=1,1+1=0 并向下一列进位 1。将两个二进制数按最低有效位对齐,从右向左计算。
Overflow occurs when the result of an addition requires more bits than the allocated register can hold. In unsigned binary, a carry out of the most significant bit indicates overflow. For example, adding 100000012 (129) and 100000012 (129) yields 1 000000102, but in an 8-bit register the leading 1 is lost, giving 000000102 (2), which is incorrect.
当加法结果需要的位数超出分配的寄存器位数时,会发生溢出。在无符号二进制中,最高位有进位即表示溢出。例如,将 100000012(129)与 100000012(129)相加,结果为 1 000000102,但在 8 位寄存器中最高位的 1 会丢失,得到 000000102(2),这是错误的。
In exams, you must be able to identify overflow conditions and explain why they occur. When dealing with signed numbers using two’s complement, overflow detection involves examining the carry into and out of the sign bit.
考试中必须能够识别溢出条件并解释其原因。当使用补码处理有符号数时,溢出检测涉及检查符号位的进位输入与输出。
6. Two’s Complement Representation | 补码表示
Two’s complement is the standard method for representing signed integers in binary. It allows addition and subtraction to be performed with the same hardware. In an 8-bit system, the most significant bit (MSB) is the sign bit: 0 for positive, 1 for negative. The positive range is 0 to 127, and the negative range is -1 to -128.
补码是二进制中表示有符号整数的标准方法。它使得加法与减法可以使用相同的硬件完成。在 8 位系统中,最高位(MSB)为符号位:0 表示正数,1 表示负数。正数范围为 0 至 127,负数范围为 -1 至 -128。
To obtain the two’s complement of a negative number, first write the binary of its absolute value, then invert all bits (one’s complement), and finally add 1. Example: to represent -5 in 8-bit two’s complement, start with +5 = 000001012, invert to 111110102, then add 1 to get 111110112.
要得到一个负数的补码,首先写出其绝对值的二进制形式,然后反转所有位(反码),最后加 1。例如:用 8 位补码表示 -5,先取 +5 = 000001012,反转为 111110102,再加 1 得到 111110112。
To convert a negative two’s complement number back to decimal, you can invert and add 1 to find its magnitude, then attach the negative sign. Alternatively, treat the MSB as -128 and add the positive contributions of the remaining bits.
将负的补码数转换回十进制时,可以再次反转加 1 求得其绝对值,然后加上负号。另一种方法是将 MSB 视为 -128,再加上其余位的正值贡献。
IB HL and WJEC A-level often ask for binary arithmetic using two’s complement, including subtraction via addition: A – B = A + (two’s complement of B).
IB 高级和 WJEC A-level 常要求使用补码进行二进制算术,包括通过加法实现减法:A – B = A +(B 的补码)。
7. Binary Shifts: Logical and Arithmetic | 二进制移位:逻辑移位与算术移位
Shifting bits left or right corresponds to multiplying or dividing by powers of two. A logical left shift moves all bits one position left, filling the rightmost bit with 0. Each left shift doubles the number, provided no overflow occurs. A logical right shift moves bits right, filling the leftmost bit with 0, effectively performing integer division by 2 for unsigned numbers.
将位向左或向右移动相当于乘以或除以 2 的幂。逻辑左移将所有位向左移动一位,最右位补 0。每左移一次数翻倍,前提是不发生溢出。逻辑右移将位向右移动,最左位补 0,对于无符号数等同于整除 2。
Arithmetic shifts preserve the sign bit when dealing with signed numbers. An arithmetic right shift copies the sign bit into the new positions, so negative numbers remain negative after division by powers of two. This is crucial for two’s complement division.
算术移位在处理有符号数时保留符号位。算术右移会将符号位复制到空出的位中,因此负数在除以 2 的幂后仍保持为负数。这对于补码除法至关重要。
Example: 8-bit arithmetic right shift on 110100102 (a negative number) gives 111010012. Notice the MSB 1 is replicated. WJEC exams often include questions requiring you to perform a given number of shifts and state the effect on the value.
示例:对 110100102(一个负数)进行 8 位算术右移,得到 111010012。注意最高位 1 被复制。WJEC 考试常包含要求执行指定次数移位并说明对数值影响的题目。
8. Character Encoding: ASCII and Unicode | 字符编码:ASCII 与 Unicode
Text characters must be represented as binary codes for storage and transmission. ASCII (American Standard Code for Information Interchange) originally used 7 bits, encoding 128 characters including letters, digits, punctuation, and control characters. Extended ASCII uses 8 bits to include additional symbols and accented characters.
文本字符必须以二进制代码表示以便存储和传输。ASCII 码最初使用 7 位,编码 128 个字符,包括字母、数字、标点和控制字符。扩展 ASCII 使用 8 位,涵盖了额外的符号和重音字符。
Unicode was developed to support a far wider range of characters from different writing systems. UTF-8, a common Unicode encoding, uses 1 to 4 bytes per character, backward compatible with ASCII. The binary representation of ‘A’ in ASCII is 010000012 (6510), and it remains the same in UTF-8.
Unicode 旨在支持来自不同书写系统的更广泛的字符。常用的 Unicode 编码 UTF-8 每个字符使用 1 到 4 字节,并与 ASCII 向后兼容。字符 ‘A’ 的 ASCII 二进制编码为 010000012(6510),在 UTF-8 中相同。
Exam questions might ask you to calculate the storage needed for a text file given the encoding (e.g., ASCII uses 1 byte per character) or to compare ASCII and Unicode advantages.
考题可能要求根据给定编码(例如 ASCII 每个字符 1 字节)计算文本文件的存储空间,或比较 ASCII 与 Unicode 的优缺点。
| Character | ASCII Binary (7-bit) | Decimal |
| ‘0’ | 011 0000 | 48 |
| ‘A’ | 100 0001 | 65 |
| ‘a’ | 110 0001 | 97 |
9. Binary Representation of Sound and Images | 声音与图像的二进制表示
Analogue sound is converted to digital by sampling the wave amplitude at regular intervals. Two key parameters affect quality: sampling rate (samples per second, measured in Hz) and bit depth (bits per sample). The file size for uncompressed audio can be calculated as: Sampling Rate × Bit Depth × Number of Channels × Duration (in seconds).
模拟声音通过以规则间隔对波形振幅采样转换为数字信号。影响质量的两个关键参数:采样率(每秒采样数,单位 Hz)和位深度(每样本位数)。未压缩音频的文件大小可按下式计算:采样率 × 位深度 × 声道数 × 时长(秒)。
For images, the image is divided into a grid of pixels; the color of each pixel is stored as a binary value. The bit depth determines the number of available colors (e.g., 8-bit color allows 256 colors, 24-bit allows about 16.7 million). Higher resolution (more pixels) and greater color depth increase quality and file size.
对于图像,图像被划分为像素网格;每个像素的颜色以二进制值存储。位深度决定可用的颜色数量(例如 8 位色彩允许 256 种颜色,24 位允许约 1670 万种)。更高的分辨率(更多像素)和更大的色彩位深会提高质量,也会增加文件大小。
Calculating image file size: Width in pixels × Height in pixels × Bit Depth (in bits), then convert to bytes as needed. Both IB and WJEC syllabi expect you to perform such calculations and comment on the trade-off between quality and storage.
计算图像文件大小:像素宽度 × 像素高度 × 位深度(以位计),必要时转换为字节。IB 和 WJEC 大纲都要求能够进行此类计算,并评论质量与存储之间的权衡。
10. Floating Point Representation (IB HL & WJEC A-level) | 浮点数表示(IB 高级与 WJEC A-level)
Real numbers are stored in binary using floating point representation, which splits a number into a mantissa (significant digits) and an exponent (power of the base). This allows a wide range of values, including very small fractions and very large numbers.
实数使用浮点表示法以二进制存储,该方法将数字拆分为尾数(有效数字)和指数(基数的幂)。这样可以表示极大范围的值,包括极小的分数和极大的数。
In typical 16-bit or 32-bit formats, a certain number of bits are allocated to the mantissa and exponent, with separate sign bits. For example, a 16-bit representation may use 10 bits for the mantissa and 6 bits for the exponent, both in two’s complement. A number is normalised to maximise precision by ensuring the mantissa’s most significant bit is different from the sign bit.
在典型的 16 位或 32 位格式中,一定数量的位分配给尾数和指数,并设有独立的符号位。例如,16 位表示可能使用 10 位尾数和 6 位指数,两者均为补码。通过确保尾数的最高有效位与符号位不同,对数字进行规格化以实现最大精度。
To derive the decimal value, the formula is: (−1)Sign × Mantissa × 2Exponent. Normalisation ensures the mantissa lies in the range 0.5 ≤ |M| < 1 (for positive) or -1 ≤ M < -0.5 (for negative). Exam questions often ask for conversion between decimal and a given floating point format, or to identify the largest/smallest representable numbers.
推导十进制值的公式为:(−1)Sign × 尾数 × 2指数。规格化确保尾数在 0.5 ≤ |M| < 1(正数)或 -1 ≤ M < -0.5(负数)范围内。考试题目常要求进行十进制与给定浮点格式之间的转换,或识别可表示的最大/最小数值。
11. Exam-Style Questions and Common Pitfalls | 考试题型与常见误区
Binary topics are examined through calculation, conversion, and explanation questions. Common pitfalls include misaligning bits during addition, confusing signed and unsigned overflow, forgetting to add leading zeros for a fixed-width representation, and incorrect two’s complement conversion (e.g., only inverting without adding 1).
二进制主题通过计算、转换和解释题进行考查。常见误区包括加法时位未对齐、混淆有符号和无符号溢出、忘记固定位数表示时补前导零,以及补码转换错误(如
Published by TutorHao | IB Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导