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

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

Binary is the fundamental language of computers, representing all data and instructions as sequences of 0s and 1s. In the IB and OCR specifications, a solid understanding of binary number systems, conversions, arithmetic, and representation of negative and floating‑point numbers is essential. This article covers the core topics you need to master, with clear explanations and paired bilingual examples to reinforce your learning.

二进制是计算机的基础语言,所有数据和指令都以 0 和 1 的序列表示。在 IB 和 OCR 考纲中,扎实掌握二进制数制、转换、运算以及负数和浮点数的表示至关重要。本文涵盖你需要掌握的核心主题,通过清晰讲解和中英双语示例来强化理解。

1. Why Binary? | 为什么采用二进制?

Computers use binary because digital circuits have two stable states: ON (1) and OFF (0). Transistors act as switches that can be easily combined to perform logic and arithmetic. This simplicity makes systems reliable and scalable. Every piece of data — numbers, text, images, sound — is ultimately stored as binary digits (bits).

计算机之所以采用二进制,是因为数字电路有两种稳定状态:开(1)和关(0)。晶体管作为开关,可以轻松组合以执行逻辑和算术运算。这种简单性使系统可靠且可扩展。每一份数据——数字、文本、图像、声音——最终都以二进制位(比特)存储。


2. Binary to Denary Conversion | 二进制转十进制

To convert a binary number to denary (decimal), multiply each bit by its place value (power of 2) and sum the results. For example, the binary number 1101₂ is calculated as (1 × 2³) + (1 × 2²) + (0 × 2¹) + (1 × 2⁰) = 8 + 4 + 0 + 1 = 13₁₀. Place values increase from right to left: 1, 2, 4, 8, 16, etc.

将二进制数转换为十进制时,将每一位乘以其位权(2 的幂)并求和。例如,二进制数 1101₂ 计算如下:(1 × 2³) + (1 × 2²) + (0 × 2¹) + (1 × 2⁰) = 8 + 4 + 0 + 1 = 13₁₀。位权从右向左递增:1, 2, 4, 8, 16……


3. Denary to Binary Conversion | 十进制转二进制

Two common methods are repeated division by 2 and subtraction of largest powers of 2. In the division method, divide the denary number by 2, record the remainder (0 or 1) as the least significant bit, and repeat with the quotient until it becomes 0. For 25₁₀: 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 upwards gives 11001₂.

两种常用方法是除以 2 取余法和 2 的幂相减法。在相除取余法中,将十进制数除以 2,记录余数(0 或 1)作为最低有效位,并用商重复此过程,直到商为 0。对于 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 | 十六进制系统

Hexadecimal (base‑16) uses digits 0–9 and letters A–F to represent values 0–15. It provides a compact way to express binary numbers: each hex digit corresponds to exactly four bits (a nibble). For example, 1011 1101₂ = BD₁₆ because 1011₂ = B (11) and 1101₂ = D (13). Hex is widely used in memory addresses, colour codes, and machine code.

十六进制(基数为 16)使用数字 0–9 和字母 A–F 来表示值 0–15。它提供了一种紧凑表达二进制数的方式:每个十六进制数字正好对应四个二进制位(半字节)。例如,1011 1101₂ = BD₁₆,因为 1011₂ = B (11) 而 1101₂ = D (13)。十六进制广泛用于内存地址、颜色代码和机器码。


5. Binary Addition | 二进制加法

Binary addition follows simple rules: 0+0=0, 0+1=1, 1+0=1, 1+1=0 carry 1, and 1+1+carry=1 carry 1. Work from rightmost bit to leftmost, handling carries. Example: 1011₂ (11) + 0110₂ (6) yields 10001₂ (17). Attention to overflow when the result exceeds the allocated number of bits.

二进制加法遵循简单规则:0+0=0,0+1=1,1+0=1,1+1=0 进位 1,以及 1+1+进位=1 进位 1。从最右位向左运算,处理进位。示例:1011₂ (11) + 0110₂ (6) 结果为 10001₂ (17)。当结果超出分配位数时需注意溢出。


6. Overflow and its Detection | 溢出及其检测

Overflow occurs when a calculation produces a result that requires more bits than the allocated register size. In signed arithmetic, overflow happens when adding two positive numbers gives a negative result, or adding two negatives gives a positive, due to carry into the sign bit. Detection uses the carry into and out of the most significant bit (MSB) — if they differ, overflow has occurred.

当计算结果需要的位数超出寄存器分配的大小时,就会发生溢出。在有符号运算中,当两个正数相加得到负数,或两个负数相加得到正数时,由于符号位进位而产生溢出。检测利用最高有效位(MSB)的进位和出位——如果两者不同,则发生了溢出。


7. Sign–Magnitude Representation | 原码表示法

In sign–magnitude, the MSB represents the sign (0 for positive, 1 for negative) and the remaining bits represent the magnitude. For an 8‑bit number, +18 = 0001 0010 and –18 = 1001 0010. Drawbacks include two representations of zero (0000 0000 and 1000 0000) and complicated arithmetic logic.

在原码表示法中,最高有效位代表符号(0 表示正,1 表示负),其余位表示数值大小。对于 8 位数,+18 = 0001 0010,–18 = 1001 0010。缺点包括零有两种表示(0000 0000 和 1000 0000),且算术逻辑复杂。


8. Two’s Complement | 二进制补码

Two’s complement is the standard method for representing signed integers. To obtain the two’s complement of a number: invert all bits (one’s complement) and add 1 to the least significant bit. For –18 in 8‑bit: +18 = 0001 0010 → invert = 1110 1101 → add 1 = 1110 1110. Two’s complement simplifies subtraction to addition, and there is only one zero.

二进制补码是表示有符号整数的标准方法。求一个数的补码:将所有位取反(反码),然后在最低有效位加 1。8 位下的 –18:+18 = 0001 0010 → 取反 = 1110 1101 → 加 1 = 1110 1110。补码将减法简化为加法,且零只有一种表示。


9. Range of Integer Representations | 整数表示的范围

For n bits, unsigned integers range from 0 to 2ⁿ – 1 (e.g., 8 bits: 0 to 255). Sign–magnitude and one’s complement range from –(2ⁿ⁻¹ – 1) to (2ⁿ⁻¹ – 1). Two’s complement has an asymmetric range: from –2ⁿ⁻¹ to (2ⁿ⁻¹ – 1). For 8 bits, two’s complement spans –128 to +127, making it more efficient for representing negatives.

对于 n 位,无符号整数范围从 0 到 2ⁿ – 1(例如 8 位:0 到 255)。原码和反码范围从 –(2ⁿ⁻¹ – 1) 到 (2ⁿ⁻¹ – 1)。补码的范围不对称:从 –2ⁿ⁻¹ 到 (2ⁿ⁻¹ – 1)。对于 8 位,补码跨度为 –128 到 +127,表示负数更高效。


10. Binary Coded Decimal (BCD) | 二进制编码十进制

BCD represents each decimal digit by its own 4‑bit binary sequence (e.g., 0 → 0000, 9 → 1001). The denary number 29 is coded as 0010 1001 in BCD. It is used in systems requiring precise decimal representation (like calculators and financial applications) but is less storage‑efficient than pure binary.

BCD 用独立的 4 位二进制序列表示每个十进制数字(例如 0 → 0000,9 → 1001)。十进制数 29 在 BCD 中编码为 0010 1001。它用于需要精确小数表示的系统(如计算器和金融应用),但存储效率低于纯二进制。


11. Floating‑Point Binary | 浮点二进制

Real numbers are stored in floating‑point format, typically using the IEEE 754 standard. A number is expressed as ± mantissa × 2^(exponent). The mantissa holds the significant digits (normalised so the first bit is 1), and the exponent is stored in biased form. For example, single precision uses 1 sign bit, 8 exponent bits (bias 127), and 23 mantissa bits. Binary fractions use negative powers of two: 0.101₂ = ½ + ⅛ = 0.625₁₀.

实数以浮点格式存储,通常采用 IEEE 754 标准。一个数表示为 ± 尾数 × 2^(指数)。尾数存放有效数字(归一化使第一位为 1),指数以偏置形式存储。例如,单精度使用 1 位符号、8 位指数(偏置 127)和 23 位尾数。二进制小数使用 2 的负次幂:0.101₂ = ½ + ⅛ = 0.625₁₀。


12. Bitwise Logical Operations | 按位逻辑运算

Binary data is often manipulated using logical operations: AND, OR, XOR, and NOT. AND outputs 1 only if both bits are 1; OR outputs 1 if at least one bit is 1; XOR outputs 1 if bits are different; NOT flips each bit. These operations are fundamental for masking, setting/clearing flags, and encryption. Example: 1100₂ AND 1010₂ = 1000₂.

二进制数据常通过逻辑运算操作:与(AND)、或(OR)、异或(XOR)和非(NOT)。与运算仅当两位均为 1 时输出 1;或运算若至少一位为 1 则输出 1;异或运算若两位不同则输出 1;非运算将每位取反。这些运算对于屏蔽、设置/清除标志和加密至关重要。示例:1100₂ AND 1010₂ = 1000₂


Published by TutorHao | 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