📚 Binary Numbers: Key Exam Points for IB and CCEA Computer Science | IB CCEA 计算机二进制考点精讲
Binary is the foundational number system for all modern computers, representing data using only two digits: 0 and 1. Both IB and CCEA Computer Science curricula place strong emphasis on understanding binary representation, arithmetic, and conversion methods. This article distills the essential binary topics you need to master for exams.
二进制是现代计算机的基础数字系统,仅使用 0 和 1 两个数字来表示数据。IB 和 CCEA 计算机科学课程都对理解二进制表示、运算和转换方法提出了高要求。本文梳理了考试必须掌握的核心二进制考点。
1. Number Systems Overview | 数制概述
Computers internally store and process data in binary (base‑2), while humans commonly use denary (base‑10). Hexadecimal (base‑16) serves as a compact shorthand for binary. Each digit in a positional number system holds a place value that is a power of the base. In binary the place values are powers of 2, starting from 2⁰ for the least significant bit.
计算机内部以二进制(基数为2)存储和处理数据,而人类通常使用十进制(基数为10)。十六进制(基数为16)是二进制的紧凑简写形式。在按位计数系统中,每个数字的位值是基数的幂。二进制的位值是2的幂,最低有效位从2⁰开始。
The binary system uses bits; a group of 8 bits forms a byte. Understanding place values is the key to all conversions. For example, the binary number 1011₂ has place values 2³ (8), 2² (4), 2¹ (2), and 2⁰ (1).
二进制系统使用位(bit);8位组成一个字节(byte)。理解位值是所有转换的关键。例如,二进制数 1011₂ 的位值分别是 2³ (8)、2² (4)、2¹ (2) 和 2⁰ (1)。
2. Binary to Denary Conversion | 二进制转十进制
To convert a binary number to denary, multiply each bit by its place value and sum the results. Starting from the rightmost bit (least significant), the place values are 2⁰, 2¹, 2², 2³, and so on. For example, 1101₂ = (1 × 2³) + (1 × 2²) + (0 × 2¹) + (1 × 2⁰) = 8 + 4 + 0 + 1 = 13₁₀.
要将二进制数转换为十进制,将每一位乘以其位值并求和。从最右边的位(最低有效位)开始,位值依次为 2⁰、2¹、2²、2³ 等。例如,1101₂ = (1 × 2³) + (1 × 2²) + (0 × 2¹) + (1 × 2⁰) = 8 + 4 + 0 + 1 = 13₁₀。
For larger numbers, creating a table of powers of two helps. Common exam questions ask for the denary equivalent of an 8‑bit binary pattern or to interpret a binary integer stored in a register.
对于较大的数,可以制作一张2的幂次表来辅助。常见考题要求给出8位二进制模式对应的十进制值,或解释寄存器中存储的二进制整数。
3. Denary to Binary Conversion | 十进制转二进制
Use the repeated division‑by‑2 method. Divide the denary number by 2, record the remainder (0 or 1), and repeat with the integer quotient until the quotient becomes 0. The binary result is read from the last remainder (most significant bit) to the first remainder.
使用重复除以2的方法。将十进制数除以2,记录余数(0或1),然后用整数商重复该过程,直到商为0。从最后一个余数(最高有效位)读到第一个余数,即得到二进制结果。
Example: convert 25 to binary. 25 ÷ 2 = 12 rem 1; 12 ÷ 2 = 6 rem 0; 6 ÷ 2 = 3 rem 0; 3 ÷ 2 = 1 rem 1; 1 ÷ 2 = 0 rem 1. Reading remainders bottom‑up gives 11001₂. Always state the number of bits if the question specifies a register size, padding with leading zeros.
示例:将25转换为二进制。25 ÷ 2 = 12 余1;12 ÷ 2 = 6 余0;6 ÷ 2 = 3 余0;3 ÷ 2 = 1 余1;1 ÷ 2 = 0 余1。从下往上读取余数得到 11001₂。如果题目指定了寄存器大小,务必说明位数,并在前面补零。
4. Hexadecimal System and Conversions | 十六进制及其转换
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 to represent binary data more compactly because one hex digit corresponds exactly to four binary bits (a nibble).
十六进制使用十六个符号:0‑9 和 A‑F(A=10, B=11, C=12, D=13, E=14, F=15)。由于一个十六进制数字恰好对应四位二进制(一个半字节),它被广泛用于更紧凑地表示二进制数据。
To convert binary to hex, group bits from the right into sets of four, then replace each group with its hex equivalent. For example, 11011010₂ grouped as 1101₂ (D₁₆) and 1010₂ (A₁₆) gives DA₁₆. To convert hex to binary, expand each hex digit to four bits. Conversions between hex and denary often go via binary.
要将二进制转换为十六进制,从右向左每四位一组,然后将每组替换为对应的十六进制符号。例如,11011010₂ 分组为 1101₂(D₁₆)和 1010₂(A₁₆),得到 DA₁₆。要将十六进制转换为二进制,则将每个十六进制数字展开为四位二进制。十六进制与十进制之间的转换通常借助二进制完成。
5. Binary Addition | 二进制加法
The four basic rules are: 0+0=0, 0+1=1, 1+0=1, and 1+1=0 with a carry of 1 to the next higher column. When adding multiple bits, manage carries carefully just as in denary addition. A worked example: add 1011₂ (11) and 0111₂ (7):
四个基本规则是:0+0=0、0+1=1、1+0=1,以及 1+1=0 并向下一列进位1。多位加法时,像十进制加法一样小心地处理进位。计算示例:将 1011₂ (11) 与 0111₂ (7) 相加:
1011₂ + 0111₂ = 10010₂ (with carries in third and fourth columns).
1011₂ + 0111₂ = 10010₂(第三列和第四列有进位)。
Exam questions may ask for the result of an addition in an 8‑bit register, including the effect on carry and overflow flags.
考题可能会要求在8位寄存器中进行加法,并分析对进位标志和溢出标志的影响。
6. Representing Negative Integers: Two’s Complement | 负整数表示:二进制补码
Two’s complement is the standard method for representing signed integers. In an n‑bit system, the most significant bit (MSB) is the sign bit: 0 for positive, 1 for negative. To obtain the two’s complement of a positive number, invert all bits (one’s complement) and then add 1.
补码表示法是表示有符号整数的标准方法。在n位系统中,最高有效位(MSB)为符号位:0表示正数,1表示负数。要获得正数对应的补码,先对所有位取反(反码),然后加1。
Example using 8 bits: +12 is 00001100₂. Invert bits → 11110011₂, add 1 → 11110100₂ = −12. The same process applied to a negative number yields its positive magnitude.
以8位为例:+12 表示为 00001100₂。取反 → 11110011₂,加1 → 11110100₂ = −12。将相同的过程应用于负数则可得到它对应的正数值。
7. Range and Subtraction Using Two’s Complement | 补码的范围与减法
For n bits, the two’s complement range is from −2ⁿ⁻¹ to 2ⁿ⁻¹−1. An 8‑bit system can represent integers from −128 to +127. Subtraction A − B is performed by adding A to the two’s complement of B. The carry out of the sign bit is ignored for a valid result.
对于n位,补码的表示范围是从 −2ⁿ⁻¹ 到 2ⁿ⁻¹−1。一个8位系统可表示 −128 到 +127 的整数。减法 A − B 通过将 A 加上 B 的补码来实现。符号位的进位在有效结果中被忽略。
Example: 5 − 3 in 4‑bit format. 5 = 0101₂, 3 = 0011₂, two’s complement of 3 = 1101₂. 0101₂ + 1101₂ = 10010₂, discard the carry‑out bit, leaving 0010₂ = 2.
示例:4位格式下 5 − 3。5 = 0101₂,3 = 0011₂,3的补码 = 1101₂。0101₂ + 1101₂ = 10010₂,丢弃进位输出位,得到 0010₂ = 2。
8. Overflow and Carry | 溢出与进位
Overflow occurs when the result of an arithmetic operation falls outside the representable range. In two’s complement addition, overflow happens when two numbers with the same sign produce a result with the opposite sign. It is distinct from a carry‑out of the most significant bit, which may be discarded in subtraction but is an error for addition of unsigned numbers.
当算术运算的结果超出可表示范围时,就会发生溢出。在补码加法中,如果两个符号相同的数相加得到符号相反的结果,则发生溢出。溢出不同于最高有效位的进位输出:在减法中进位输出可被丢弃,但无符号数加法中出现进位输出表示结果超出范围。
Hardware flags typically include a Carry flag and an Overflow flag. Be prepared to identify overflow conditions in exam questions, especially when given a fixed‑width register.
硬件标志通常包括进位标志和溢出标志。在考题中要能够判断溢出条件,尤其是在给定固定宽度寄存器的情况下。
9. Logical Shifts and Arithmetic Shifts | 逻辑移位与算术移位
A logical shift moves all bits one position to the left or right, filling the vacated positions with zeros. A left logical shift multiplies an unsigned binary number by 2; a right logical shift divides by 2, discarding the remainder.
逻辑移位将所有位向左或向右移动一位,空出的位用0填充。逻辑左移相当于无符号二进制数乘以2;逻辑右移相当于除以2,余数被丢弃。
An arithmetic shift right preserves the sign bit by replicating the MSB, which is essential for signed numbers. For example, arithmetically shifting 11110100₂ (−12 in 8 bits) right by one gives 11111010₂ (−6), maintaining the sign.
算术右移通过复制最高有效位来保留符号位,这对于有符号数至关重要。例如,将 11110100₂(8位中的−12)算术右移一位得到 11111010₂(−6),保持了符号。
10. Bitwise Logical Operations and Masking | 按位逻辑运算与掩码
Bitwise operators AND, OR, XOR, and NOT act on individual bits. AND is used to clear bits, OR to set bits, XOR to toggle bits, and NOT to invert all bits. A mask is a binary pattern that selects which bits to modify.
按位运算符 AND、OR、XOR 和 NOT 对各个位进行操作。AND 用于清零,OR 用于置位,XOR 用于翻转,NOT 用于将所有位取反。掩码是决定修改哪些位的二进制模式。
Example: To turn off the upper nibble of an 8‑bit value without affecting the lower nibble, AND with 00001111₂. Bitwise operations are common in low‑level programming, status registers, and permission flags.
示例:要关闭8位值的高四位而不影响低四位,可将它与 00001111₂ 做 AND 运算。按位运算常见于底层编程、状态寄存器和权限标志中。
11. Character Encoding: ASCII and Unicode | 字符编码:ASCII 与 Unicode
Characters are stored as binary numbers using standardised codes. ASCII originally used 7 bits to represent English letters, digits, and symbols (e.g., ‘A’ = 65₁₀ = 01000001₂). Extended ASCII uses 8 bits for an additional 128 characters.
字符通过标准化编码以二进制数的形式存储。ASCII 原本使用7位来表示英文字母、数字和符号(例如 ‘A’ = 65₁₀ = 01000001₂)。扩展 ASCII 使用8位,增加了额外的128个字符。
Unicode covers a vast range of characters from all writing systems. Common encoding forms are UTF‑8, UTF‑16, and UTF‑32. UTF‑8 is variable‑length (1‑4 bytes) and backwards compatible with ASCII. Exam questions may test conversions and the need for Unicode in global applications.
Unicode 涵盖了来自所有书写系统的海量字符。常见编码形式包括 UTF‑8、UTF‑16 和 UTF‑32。UTF‑8 是变长编码(1到4字节),并且与 ASCII 向后兼容。考题可能考查编码转换以及在全球应用中为何需要 Unicode。
12. Data Storage Units | 数据存储单位
The fundamental unit of data is the bit. Common groupings include a nibble (4 bits) and a byte (8 bits). Larger units use binary prefixes: 1 kibibyte (KiB) = 1024 bytes, 1 mebibyte (MiB) = 1024 KiB, 1 gibibyte (GiB) = 1024 MiB. Decimal prefixes (KB, MB, GB) are often used for storage devices but based on powers of 1000.
数据的基本单位是位。常见的分组包括半字节(4位)和字节(8位)。更大的单位使用二进制前缀:1 kibibyte (KiB) = 1024 字节,1 mebibyte (MiB) = 1024 KiB,1 gibibyte (GiB) = 1024 MiB。十进制前缀(KB、MB、GB)常用于存储设备,但基于1000的幂。
Be able to convert between these units and calculate file sizes, such as the number of bytes required for a bitmap image given its resolution and colour depth. Understanding the difference between binary and decimal prefixes is a common exam pitfall.
考生应能进行单位换算并计算文件大小,例如根据分辨率和色深计算位图图像所需的字节数。理解二进制前缀与十进制前缀的区别是考试中常见的易错点。
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课程辅导,国外大学本科硕士研究生博士课程论文辅导