📚 Data Representation Exam Essentials | 数据表示考点精讲
Data representation is the fundamental concept of how computers store, process, and transmit information in binary forms. Understanding number systems, encoding schemes, and file size calculations is essential for success in IB and CCEA Computer Science examinations.
数据表示是计算机如何以二进制形式存储、处理和传输信息的基础概念。理解数制、编码方案和文件大小计算对在 IB 和 CCEA 计算机科学考试中取得成功至关重要。
1. Number Systems: Binary, Denary, and Hexadecimal | 数制:二进制、十进制与十六进制
Computers operate using the binary number system (base 2) with digits 0 and 1. The denary system (base 10) is the everyday counting system, while hexadecimal (base 16) uses digits 0–9 and letters A–F to compactly represent binary groups of four bits.
计算机使用二进制(基数为2)运行,数字为0和1。十进制(基数为10)是日常计数系统,而十六进制(基数为16)使用数字0–9和字母A–F来紧凑地表示四位一组二进制。
A single binary digit is called a bit. Bits are combined into larger units: a nibble is 4 bits, a byte is 8 bits, a kilobyte is 1024 bytes, and so on.
单个二进制数字称为比特(bit)。比特组成更大的单位:一个半字节(nibble)是4比特,一个字节(byte)是8比特,一千字节(kilobyte)是1024字节,等等。
Hexadecimal is widely used for memory addresses, colour codes, and MAC addresses because it is more human-readable than long binary strings.
十六进制被广泛用于内存地址、颜色代码和MAC地址,因为它比长串二进制更易于人类阅读。
2. Converting Between Bases | 进制转换
To convert binary to denary, sum the place values (powers of 2) where a 1 appears. For example, 1011₂ = 1×8 + 0×4 + 1×2 + 1×1 = 11₁₀.
将二进制转换为十进制,对出现1的数位值(2的幂)求和。例如,1011₂ = 1×8 + 0×4 + 1×2 + 1×1 = 11₁₀。
To convert denary to binary, repeatedly divide by 2 and record the remainders from bottom to top. For 13, the remainders are 1, 0, 1, 1 giving 1101₂.
将十进制转换为二进制,反复除以2,从下到上记录余数。对于13,余数为1、0、1、1,得到1101₂。
Hexadecimal to binary conversion maps each hex digit to a 4-bit nibble. For example, 2F₁₆ is 0010 1111₂. Binary to hex groups bits into nibbles from the right.
十六进制到二进制转换将每个十六进制数字映射为4比特半字节。例如,2F₁₆为0010 1111₂。二进制转十六进制从右侧开始将比特分组为半字节。
| Hex Digit | Binary (nibble) | Denary |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| A | 1010 | 10 |
| F | 1111 | 15 |
3. Binary Arithmetic and Overflow | 二进制算术与溢出
Binary addition follows similar rules to denary addition: 0+0=0, 0+1=1, 1+0=1, 1+1=10 (carry 1). Adding 0110₂ (6) and 0101₂ (5) yields 1011₂ (11).
二进制加法遵循类似十进制加法的规则:0+0=0,0+1=1,1+0=1,1+1=10(进位1)。将0110₂(6)和0101₂(5)相加得到1011₂(11)。
Overflow occurs when the result of an addition exceeds the bit capacity allocated. For example, in an 8-bit register, adding 11111111₂ (255) and 00000001₂ (1) produces 100000000₂ (256), which requires 9 bits, causing an overflow error.
当加法结果超出分配的比特容量时发生溢出。例如,在一个8位寄存器中,将11111111₂(255)和00000001₂(1)相加产生100000000₂(256),这需要9比特,导致溢出错误。
Computers detect overflow using a status flag; programmers must be aware of this when working with finite storage.
计算机使用状态标志检测溢出;程序员在处理有限存储时必须意识到这一点。
4. Negative Numbers: Sign-Magnitude and Two’s Complement | 负数表示:原码与补码
Sign-magnitude representation uses the most significant bit (MSB) as the sign bit (0 for positive, 1 for negative) and the remaining bits for magnitude. For example, in 8 bits, +5 is 00000101 and -5 is 10000101.
原码表示使用最高有效位(MSB)作为符号位(0为正,1为负),其余比特表示数值大小。例如,在8位中,+5为00000101,-5为10000101。
Sign-magnitude leads to two zeros (00000000 and 10000000) and complicates addition hardware.
原码会导致两个零(00000000和10000000),并使加法硬件复杂化。
Two’s complement solves these issues. To obtain the two’s complement of a number, invert all bits and add 1. For -5: start with 00000101, invert to 11111010, add 1 → 11111011.
补码解决了这些问题。要得到一个数的补码,将所有比特取反后加1。对于-5:从00000101开始,取反为11111010,加1→11111011。
In two’s complement, subtraction is addition of the two’s complement, and there is only one zero representation.
在补码中,减法就是加上补码,并且只有一个零的表示。
Range of n-bit two’s complement: -2^(n-1) to 2^(n-1) – 1.
n位补码的范围:-2^(n-1) 到 2^(n-1) – 1。
5. Binary-Coded Decimal (BCD) | 二进码十进数(BCD)
BCD represents each denary digit with its own 4-bit binary code (0000 to 1001). For example, 25 is represented as 0010 0101 in packed BCD.
BCD用各自的4位二进制代码(0000到1001)表示每个十进制数字。例如,25在压缩BCD中表示为0010 0101。
BCD avoids fractional rounding errors in decimal-based applications (such as financial calculations) because it maintains exact decimal precision, unlike pure binary floating-point.
BCD避免了基于小数的应用(如金融计算)中的分数舍入误差,因为它保持精确的十进制精度,不同于纯二进制浮点数。
However, BCD uses more memory and is computationally slower; hardware support is less common in modern general-purpose processors.
然而,BCD使用更多内存,计算速度更慢;在现代通用处理器中硬件支持较少见。
6. Character Encoding: ASCII and Unicode | 字符编码:ASCII与Unicode
ASCII (American Standard Code for Information Interchange) uses 7 bits to represent 128 characters, including control characters, uppercase and lowercase letters, digits, and punctuation. Extended ASCII adds an 8th bit for 256 characters, including symbols for European languages.
ASCII(美国信息交换标准代码)使用7比特表示128个字符,包括控制字符、大小写字母、数字和标点符号。扩展ASCII增加了第8位以表示256个字符,包括欧洲语言的符号。
Unicode extends ASCII to support virtually all writing systems. UTF-8 is a variable-length encoding (1 to 4 bytes) that is backward-compatible with ASCII; UTF-16 uses 2 or 4 bytes per character.
Unicode扩展了ASCII以支持几乎所有书写系统。UTF-8是一种向后兼容ASCII的变长编码(1至4字节);UTF-16每个字符使用2或4字节。
Understanding encoding allows calculation of string storage requirements: e.g., a 10-character ASCII string requires 10 bytes; the same text in UTF-8 may need more if non-ASCII symbols are used.
理解编码可以计算字符串存储需求:例如,一个10字符的ASCII字符串需要10字节;如果使用了非ASCII符号,同样的文本在UTF-8中可能需要更多字节。
7. Representing Images: Bitmaps and Vector Graphics | 图像表示:位图与矢量图
A bitmap image is composed of a grid of pixels, each assigned a binary colour value. The key attributes are colour depth and resolution.
位图图像由像素网格组成,每个像素分配一个二进制颜色值。关键属性是颜色深度和分辨率。
Colour depth is the number of bits per pixel, determining the number of available colours: 1 bit → 2 colours; 8 bits → 256 colours; 24 bits (true colour) → over 16 million colours.
颜色深度是每像素的比特数,决定了可用的颜色数量:1比特→2种颜色;8比特→256种颜色;24比特(真彩色)→超过1600万种颜色。
Vector images store mathematical descriptions of shapes (lines, curves, polygons) rather than pixels, allowing infinite scaling without loss of quality. They are ideal for logos and diagrams, while bitmaps suit photographs and detailed textures.
矢量图存储形状的数学描述(线条、曲线、多边形),而不是像素,允许无限缩放而不损失质量。它们非常适合标志和图表,而位图适合照片和细致纹理。
8. Image Resolution, Colour Depth and File Size | 图像分辨率、颜色深度与文件大小
Image file size (in bits) can be calculated as: resolution width × resolution height × colour depth. To convert to bytes, divide by 8; to kilobytes, further divide by 1024.
图像文件大小(以比特计)可计算为:分辨率宽度 × 分辨率高度 × 颜色深度。转换为字节需除以8;转换为千字节需再除以1024。
File size (bits) = W × H × D
文件大小(比特)= W × H × D
For a 1920×1080 image with 24-bit colour, uncompressed size = 1920 × 1080 × 24 = 49,766,400 bits ≈ 5.93 MB.
对于1920×1080、24位颜色的图像,未压缩大小 = 1920 × 1080 × 24 = 49,766,400 比特 ≈ 5.93 MB。
Metadata (file header, palette, EXIF data) may increase the file size slightly; standard calculations often omit metadata unless specified.
元数据(文件头、调色板、EXIF数据)可能会略微增加文件大小;标准计算通常忽略元数据,除非特别说明。
9. Representing Sound: Sampling and Quantisation | 声音表示:采样与量化
Sound is an analogue waveform that must be converted to digital via sampling (measuring amplitude at discrete intervals) and quantisation (rounding each amplitude to the nearest digital value).
声音是一种模拟波形,必须通过采样(在离散间隔测量振幅)和量化(将每个振幅四舍五入到最接近的数字值)方式转换为数字形式。
The sample rate, measured in Hertz (Hz), is the number of samples per second. Common rates: 44.1 kHz (CD quality) or 48 kHz. The Nyquist theorem states the sample rate must be at least twice the highest frequency to avoid aliasing.
采样率以赫兹(Hz)为单位,是每秒的采样次数。常见速率:44.1 kHz(CD质量)或48 kHz。奈奎斯特定理指出采样率必须至少为最高频率的两倍,以避免混叠。
Bit depth (quantisation bits) determines the number of possible amplitude levels: 16-bit depth provides 65,536 levels; higher bit depth reduces quantisation noise.
位深度(量化比特)决定了可能的振幅级数:16位深度提供65,536个级别;更高的位深度可减少量化噪声。
10. Sound File Size and Bit Rate | 声音文件大小与比特率
Uncompressed sound file size (bits) = sample rate (Hz) × bit depth × number of channels × duration (seconds).
未压缩声音文件大小(比特)= 采样率(Hz)× 位深度 × 声道数 × 时长(秒)。
For a 3-minute stereo CD-quality track: 44,100 × 16 × 2 × 180 = 254,016,000 bits ≈ 30.3 MB.
对于一首3分钟的立体声CD质量音轨:44,100 × 16 × 2 × 180 = 254,016,000 比特 ≈ 30.3 MB。
Bit rate, often expressed in kbps, is the amount of data processed per second of audio: bit rate = sample rate × bit depth × channels. For CD stereo, bit rate = 44,100 × 16 × 2 = 1,411.2 kbps.
比特率通常以kbps表示,是每秒音频处理的数据量:比特率 = 采样率 × 位深度 × 声道数。对于CD立体声,比特率 = 44,100 × 16 × 2 = 1,411.2 kbps。
11. Data Compression: Lossy and Lossless | 数据压缩:有损与无损
Lossless compression reduces file size without losing any information, allowing exact reconstruction of the original data. Techniques include run-length encoding (RLE) and Huffman coding. Examples: PNG, FLAC, ZIP.
无损压缩在减小文件大小的同时不丢失任何信息,可以精确重建原始数据。技术包括游程编码(RLE)和霍夫曼编码。例如:PNG、FLAC、ZIP。
Run-length encoding replaces consecutive identical values with a count and the value. For example, ‘AAAAABBBCC’ becomes ‘5A3B2C’.
游程编码用计数和值替换连续相同的值。例如,’AAAAABBBCC’变为’5A3B2C’。
Lossy compression discards perceptually less important information to achieve higher compression ratios, and the original cannot be perfectly restored. Used for JPEG (images), MP3 (sound), and MPEG (video).
有损压缩丢弃感知上不太重要的信息以实现更高的压缩比,且原始数据无法完美还原。用于JPEG(图像)、MP3(声音)和MPEG(视频)。
The choice between lossy and lossless depends on the application: medical imaging requires lossless integrity, while streaming music benefits from lossy compression to save bandwidth.
有损与无损的选择取决于应用场景:医学影像要求无损完整性,而流媒体音乐则受益于有损压缩以节省带宽。
12. Check Digits and Simple Error Detection | 校验位与简单错误检测
A check digit is an additional digit appended to a code to verify its integrity during entry or transmission. The most common method is the modulus check, such as ISBN-13’s final digit.
校验位是附加在代码后的一位数字,用于在输入或传输过程中验证其完整性。最常见的方法是模数校验,例如ISBN-13的最后一位数字。
Parity bits are added to a binary string to make the number of 1s either even (even parity) or odd (odd parity). A single parity bit can detect an odd number of bit errors but cannot correct them.
奇偶校验位添加到二进制串中,使1的个数为偶数(偶校验)或奇数(奇校验)。单个奇偶校验位可以检测奇数个比特错误,但不能纠正它们。
More robust error detection schemes like CRC (Cyclic Redundancy Check) and checksums are used in network protocols and file integrity checks.
更强大的错误检测方案,如循环冗余校验(CRC)和校验和,被用于网络协议和文件完整性检查。
In exam questions, you may be asked to calculate a check digit using a modulo-11 algorithm or to verify a received code using parity. Understand the limitations: simple parity cannot detect even-bit errors.
在考试问题中,可能会要求你用模11算法计算校验位,或用奇偶校验验证接收到的代码。理解其局限性:简单的奇偶校验无法检测偶数比特的错误。
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课程辅导,国外大学本科硕士研究生博士课程论文辅导