📚 Information Representation for CIE AS & A Level Computer Science | CIE AS & A Level 计算机信息表示法
Information representation is the foundation of every digital system. Before a computer can store, process or transmit data, the data must be converted into a form that electronic circuits can handle. For Cambridge International AS and A Level Computer Science, this topic covers number systems, binary arithmetic, character encoding, bitmap images, sound and data compression. Mastering these ideas is essential because they appear in both Paper 1 and Paper 2 style questions.
信息表示是每个数字系统的基础。在计算机存储、处理或传输数据之前,数据必须被转换成电子电路能够处理的形式。对于剑桥国际 AS 与 A Level 计算机科学,本主题涵盖数制、二进制运算、字符编码、位图图像、声音和数据压缩。掌握这些概念至关重要,因为它们会出现在 Paper 1 和 Paper 2 类型的题目中。
1. Why Computers Use Binary | 为什么计算机使用二进制
At the hardware level, a computer is built from millions of switching circuits, such as transistors, which can reliably be in one of two states: on or off. Binary uses only two symbols, 0 and 1, and maps naturally onto these physical states. This two-state approach reduces errors caused by voltage drift, makes circuits simpler to design, and allows Boolean logic to be applied directly to processing. For this reason, all data inside a computer, including numbers, text, images and sound, is ultimately represented as patterns of bits.
在硬件层面,计算机由数百万个开关电路(如晶体管)构成,这些电路只能可靠地处于两种状态之一:导通或截止。二进制仅使用 0 和 1 两个符号,恰好与这些物理状态自然对应。这种双状态方法减少了电压漂移引起的错误,使电路设计更简单,并允许布尔逻辑直接用于处理。因此,计算机内部的所有数据,包括数字、文本、图像和声音,最终都以比特模式表示。
2. Number Systems: Denary, Binary and Hexadecimal | 数制:十进制、二进制与十六进制
The Cambridge AS & A Level syllabus expects you to work confidently with three number systems. Denary (base 10) uses digits 0-9. Binary (base 2) uses 0 and 1. Hexadecimal (base 16) uses 0-9 and A-F, where A=10, B=11, C=12, D=13, E=14 and F=15. Programmers often use hexadecimal because it compactly represents a nibble (4 bits) and maps one-to-one onto a group of four binary digits.
剑桥 AS 与 A Level 大纲要求你熟练掌握三种数制。十进制(基数为 10)使用数字 0-9。二进制(基数为 2)使用 0 和 1。十六进制(基数为 16)使用 0-9 和 A-F,其中 A=10、B=11、C=12、D=13、E=14、F=15。程序员经常使用十六进制,因为它能够紧凑地表示一个半字节(4 位),并与一组四位二进制一一对应。
| Denary | Binary (4-bit) | Hex |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
Binary Coded Decimal (BCD) is another representation sometimes tested in the syllabus. In BCD, each denary digit is stored separately using four bits. For example, 29 is stored as 0010 1001. This is useful in devices such as digital clocks and calculators because it simplifies the display of decimal digits, but it is less space-efficient than pure binary.
二进制编码的十进制(BCD)是本大纲中有时会考查的另一种表示法。在 BCD 中,每个十进制数字分别用四位存储。例如,29 被存储为 0010 1001。这在数字时钟和计算器等设备中很有用,因为它简化了十进制数字的显示,但它的空间效率低于纯二进制。
3. Converting Between Number Systems | 数制之间的转换
To convert a binary integer to denary, multiply each bit by its place value, which is a power of 2. The rightmost bit has place value 2⁰, the next 2¹, then 2², and so on. For example, the binary number 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₁₀。
To convert denary to binary, repeatedly divide the denary number by 2 and record the remainder each time. The binary result is the remainders read from bottom to top. To convert between binary and hexadecimal, split the binary number into groups of four bits from the right, then replace each group with the matching hexadecimal digit. Pad the leftmost group with zeros if needed.
要将十进制转换为二进制,反复将十进制数除以 2,并记录每次的余数。二进制结果是从下往上读取余数。要在二进制和十六进制之间转换,从右侧将二进制数每四位分成一组,然后将每组替换为对应的十六进制数字。如果需要,在最左侧的一组前补零。
- Example: 10111101₂ = 1011 1101 = BD₁₆
- Example: 3F₁₆ = 0011 1111 = 00111111₂
- Example: 45₁₀ = 32+8+4+1 = 101101₂
4. Binary Addition and Overflow | 二进制加法与溢出
Binary addition follows four simple rules: 0+0=0, 0+1=1, 1+0=1, and 1+1=10, which means write 0 and carry 1 to the next column. When adding two bits plus a carry, 1+1+1=11, so write 1 and carry 1. These rules allow the addition of any two unsigned binary integers.
二进制加法遵循四条简单规则:0+0=0、0+1=1、1+0=1、1+1=10,这意味着写 0 并向下一列进位 1。当两个位加上一个进位相加时,1+1+1=11,所以写 1 并进位 1。这些规则允许对任意两个无符号二进制整数进行加法运算。
Overflow occurs when the result of an addition requires more bits than the register or storage location can hold. For example, in an 8-bit system, adding 11111111₂ (255) and 00000001₂ (1) gives 100000000₂, which needs 9 bits. The hardware would store only the lower 8 bits, producing an incorrect result. Exam questions often ask you to identify when overflow has occurred and to explain its cause.
当加法结果所需的位数超过寄存器或存储单元所能容纳的位数时,就会发生溢出。例如,在 8 位系统中,将 11111111₂(255)与 00000001₂(1)相加得到 100000000₂,这需要 9 位。硬件只会存储低 8 位,从而产生错误结果。考试题经常要求你识别何时发生溢出并解释其原因。
5. Representing Negative Numbers: Sign-and-Magnitude and Two’s Complement | 负数表示:原码与补码
Two methods are commonly used to represent negative integers: sign-and-magnitude and two’s complement. In sign-and-magnitude, the most significant bit (MSB) represents the sign: 0 for positive, 1 for negative. The remaining bits store the magnitude. For example, in 8 bits, +5 is 00000101 and -5 is 10000101. This method is easy for humans to read but creates two representations of zero and complicates arithmetic.
通常使用两种方法来表示负整数:原码和补码。在原码中,最高有效位表示符号:0 表示正,1 表示负。其余位存储数值大小。例如,在 8 位中,+5 为 00000101,-5 为 10000101。这种方法便于人类阅读,但会产生两个零的表示,并使算术运算复杂化。
Two’s complement is the most widely used method in modern computers. To find the two’s complement of a negative number, first write the positive magnitude in binary, then invert all bits (one’s complement), and finally add 1. For an n-bit register, two’s complement can represent integers from -2ⁿ⁻¹ to 2ⁿ⁻¹-1. For an 8-bit register, the range is -128 to +127.
补码是现代计算机中最广泛使用的方法。要找到负数的补码,首先写出正数大小的二进制形式,然后将所有位取反(反码),最后加 1。对于 n 位寄存器,补码可以表示从 -2ⁿ⁻¹ 到 2ⁿ⁻¹-1 的整数。对于 8 位寄存器,范围是 -128 到 +127。
Two’s complement of N = 2ⁿ − N
6. Binary Subtraction Using Two’s Complement | 使用补码进行二进制减法
Binary subtraction can be performed by converting the number being subtracted into its two’s complement and then adding it to the first number. The result is correct when the extra carry beyond the register size is discarded. For example, to calculate 0110₂ (6) − 0011₂ (3), find the two’s complement of 0011: invert to 1100, add 1 to get 1101. Then add 0110 + 1101 = 10011. Discard the leading carry to leave 0011, which is 3 in denary.
二进制减法可以通过将要减的数转换为其补码,然后将其与第一个数相加来实现。当超出寄存器大小的额外进位被丢弃时,结果就是正确的。例如,计算 0110₂(6)− 0011₂(3),求 0011 的补码:取反得到 1100,加 1 得到 1101。然后相加 0110 + 1101 = 10011。丢弃前导进位,剩下 0011,即十进制中的 3。
This approach simplifies processor design because the same adder circuit can handle both addition and subtraction. Candidates should practise converting negative numbers into two’s complement quickly and accurately, as this skill is often tested in structured questions.
这种方法简化了处理器设计,因为同一个加法器电路可以处理加法和减法。考生应练习快速、准确地将负数转换为补码,因为这项技能经常在结构化问题中考查。
7. Binary Multiplication and Logical Shifts | 二进制乘法与逻辑移位
Multiplying a binary number by 2 can be achieved by shifting every bit one place to the left and filling the empty rightmost position with 0. For example, 0011₂ (3) shifted left once becomes 0110₂ (6). Shifting left by n positions multiplies the original value by 2ⁿ. Similarly, shifting right by n positions divides the value by 2ⁿ for positive integers, with the remainder being discarded in a logical shift.
将二进制数乘以 2 可以通过将每一位向左移动一位并在空出的最右位置补 0 来实现。例如,0011₂(3)左移一位后变为 0110₂(6)。左移 n 位相当于将原值乘以 2ⁿ。类似地,右移 n 位相当于将正整数值除以 2ⁿ,逻辑移位中余数会被丢弃。
Left shift n places: value × 2ⁿ
Logical shifts always fill the vacant positions with zeros. Arithmetic shifts, used for signed numbers, preserve the sign bit when shifting right. It is important to read the question carefully and state whether a logical or arithmetic shift is being used.
逻辑移位总是用零填充空出的位置。用于有符号数的算术移位在右移时会保留符号位。仔细阅读题目并说明使用的是逻辑移位还是算术移位非常重要。
8. Character Encoding: ASCII and Unicode | 字符编码:ASCII 与 Unicode
Text characters must be represented as binary codes so that computers can store and process them. ASCII (American Standard Code for Information Interchange) originally used 7 bits to represent 128 characters, including upper-case and lower-case letters, digits, punctuation and control characters. Extended ASCII uses 8 bits and can represent 256 characters.
文本字符必须表示为二进制代码,计算机才能存储和处理它们。ASCII(美国信息交换标准代码)最初使用 7 位表示 128 个字符,包括大写和小写字母、数字、标点符号以及控制字符。扩展 ASCII 使用 8 位,可以表示 256 个字符。
ASCII is limited because it cannot represent characters from most non-Latin writing systems. Unicode solves this problem by providing a unique code point for every character in virtually all of the world’s writing systems. Common Unicode encodings include UTF-8, UTF-16 and UTF-32. UTF-8 is variable-length and is backward compatible with ASCII, making it very widely used on the internet.
ASCII 的局限性在于它无法表示大多数非拉丁文字系统的字符。Unicode 通过为世界上几乎所有文字系统中的每个字符提供唯一的码点来解决这个问题。常见的 Unicode 编码包括 UTF-8、UTF-16 和 UTF-32。UTF-8 是可变长度的,并且向后兼容 ASCII,因此在互联网上被广泛使用。
9. Representing Bitmap Images | 位图图像表示
A bitmap image is made up of a rectangular grid of small squares called pixels. Each pixel is assigned a binary value that determines its colour. The number of bits used for each pixel is called the colour depth. A 1-bit image can only store two colours, while a 24-bit image can store about 16.7 million colours.
位图图像由称为像素的小方块组成的矩形网格构成。每个像素被赋予一个决定其颜色的二进制值。用于每个像素的位数称为颜色深度。1 位图像只能存储两种颜色,而 24 位图像可以存储约 1670 万种颜色。
The resolution of an image is the number of pixels it contains, usually stated as width × height. The file size of an uncompressed bitmap can be calculated using the formula below. Remember to divide by 8 if the answer is required in bytes rather than bits.
图像的分辨率是它所包含的像素数量,通常表示为宽度 × 高度。未压缩位图的文件大小可以使用下面的公式计算。如果答案要求以字节为单位而不是位,请记得除以 8。
Image file size = width × height × colour depth
For example, a 100 × 100 image with a colour depth of 8 bits has a file size of 100 × 100 × 8 = 80,000 bits = 10,000 bytes.
例如,一张 100 × 100、颜色深度为 8
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课程辅导,国外大学本科硕士研究生博士课程论文辅导