Data Representation | 数据表示

📚 Data Representation | 数据表示

In A-Level OCR Computer Science, data representation forms the bedrock of understanding how computers store, process and communicate information. From number bases and floating-point arithmetic to character encoding and multimedia formats, this topic links mathematics with the physical reality of binary circuits. Mastering these concepts is essential not only for the exam but also for grasping how high-level programs ultimately become bit patterns in memory.

在A-Level OCR计算机科学中,数据表示是理解计算机如何存储、处理和传递信息的基石。从数制和浮点运算到字符编码与多媒体格式,这一主题将数学与二值电路的物理现实连接起来。掌握这些概念不仅对考试至关重要,也有助于理解高级程序最终如何变成内存中的位模式。

1. Number Bases: Binary, Denary and Hexadecimal | 数制:二进制、十进制与十六进制

Computers use binary (base-2) because transistors have two stable states. Denary (base-10) is our everyday system, while hexadecimal (base-16) compresses four bits into one symbol (0–F), making it easier to read long binary strings.

计算机使用二进制(基数为2)是因为晶体管有两种稳定状态。十进制(基数为10)是我们的日常系统,而十六进制(基数为16)将四个比特压缩成一个符号(0–F),使得长二进制串更易读。

To convert binary to denary: multiply each bit by its place value (powers of 2) and sum the results. For example, 1011₂ = 1×8 + 0×4 + 1×2 + 1×1 = 11₁₀.

二进制转十进制:将每个比特乘以其位权(2的幂)并求和。例如,1011₂ = 1×8 + 0×4 + 1×2 + 1×1 = 11₁₀。

Denary to binary: repeatedly divide the denary number by 2, recording the remainders; read them backwards. 13₁₀ → 1101₂.

十进制转二进制:不断将十进制数除以2,记录余数;反向读取余数。13₁₀ → 1101₂。

Hexadecimal to binary: replace each hex digit with its 4-bit nibble. A2₁₆ = 1010 0010₂. Binary to hex: group bits from the right into nibbles and convert each.

十六进制转二进制:将每个十六进制数字替换为其4位半字节。A2₁₆ = 1010 0010₂。二进制转十六进制:从右向左将比特分组为半字节,再分别转换。

  • Denary 0–9 → hex 0–9
  • Denary 10–15 → hex A–F
  • 十进制0–9 → 十六进制0–9
  • 十进制10–15 → 十六进制A–F

2. Binary Arithmetic and Two’s Complement | 二进制算术与补码表示

Binary addition follows simple rules: 0+0=0, 0+1=1, 1+1=0 (carry 1), 1+1+1=1 (carry 1). Overflow occurs when a result exceeds the bit width allocated, causing the most significant carry to be lost.

二进制加法遵循简单规则:0+0=0, 0+1=1, 1+1=0(进位1), 1+1+1=1(进位1)。当结果超出分配的位宽时发生溢出,最高位进位会丢失。

Negative numbers are represented using two’s complement. To negate a number: invert all bits and add 1. For an 8-bit register, 5₁₀ = 00000101₂; −5 = 11111011₂. The most significant bit (MSB) acts as the sign bit: 0 for positive, 1 for negative.

负数使用补码(two’s complement)表示。求负数:将所有位取反后加1。对于8位寄存器,5₁₀ = 00000101₂;−5 = 11111011₂。最高有效位(MSB)充当符号位:0表示正,1表示负。

Range of an n-bit two’s complement integer: −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1. For 8 bits: −128 to 127. Subtraction is performed by adding the two’s complement of the subtrahend.

n位补码整数的范围:−2ⁿ⁻¹ 到 2ⁿ⁻¹ − 1。8位时:−128到127。减法通过对减数取补码后相加来实现。

Operation (操作) Binary example (8-bit) Result (结果)
5 + 3 00000101 + 00000011 00001000 (8)
5 – 3 00000101 + 11111101 00000010 (2)

3. Floating-Point Binary | 二进制浮点表示

Real numbers are stored in floating-point form: mantissa × baseᵉˣᵖᵒⁿᵉⁿᵗ. In OCR’s specification, we use mantissa (signed fraction) and exponent (signed integer), both in two’s complement, with an implied binary point after the sign bit of the mantissa.

实数以浮点形式存储:尾数 × 基数 指数。在OCR规范中,我们使用尾数(带符号小数)和阶码(带符号整数),两者均用补码,隐含的小数点在尾数符号位之后。

Normalisation: adjust the mantissa and exponent so that the first two bits of the mantissa are different (01 or 10). This maximises precision and ensures a unique representation.

规格化:调整尾数和阶码,使尾数的前两位不同(01或10)。这最大化精度并确保表示唯一。

Steps to normalise: shift the mantissa left or right, adjusting the exponent accordingly. For example, with 8-bit mantissa and 4-bit exponent, 0.1100₂ × 2⁰ → normalised 0.1100₂ × 2⁰ (already normalised). If the mantissa was 0.0011₂, left-shift by two places to 0.1100₂, and subtract 2 from the exponent.

规格化步骤:左移或右移尾数,并相应调整阶码。例如,使用8位尾数、4位阶码,0.1100₂ × 2⁰ → 规格化 0.1100₂ × 2⁰(已经规格化)。如果尾数为0.0011₂,左移两位至0.1100₂,阶码减2。

Largest positive normalised number (8-bit mantissa, 4-bit exponent): mantissa = 0.1111111₂, exponent = 0111₂ (7), value ≈ 0.1111111₂ × 2⁷ = 127/128 × 128 ≈ 127.

最大正规格化数(8位尾数,4位阶码):尾数 = 0.1111111₂,阶码 = 0111₂ (7),值 ≈ 0.1111111₂ × 2⁷ = 127/128 × 128 ≈ 127。

Converting from denary: express the number as a normalised binary fraction. 5.75₁₀ = 101.11₂ = 0.10111₂ × 2³. Mantissa (8 bits): 01011100 (0.1011100₂), exponent (4 bits): 0011₂ (3).

从十进制转换:将数字表示为规格化的二进制小数。5.75₁₀ = 101.11₂ = 0.10111₂ × 2³。尾数(8位):01011100 (0.1011100₂),阶码(4位):0011₂ (3)。


4. Character Encoding: ASCII and Unicode | 字符编码:ASCII与Unicode

Characters are assigned numeric codes so they can be stored as bit patterns. ASCII (American Standard Code for Information Interchange) originally used 7 bits, providing 128 characters (0–31 control, 32–127 printable). Extended ASCII uses 8 bits for 256 characters, adding accented letters and symbols.

字符被分配数字编码,以便作为位模式存储。ASCII(美国信息交换标准代码)最初使用7位,提供128个字符(0–31为控制字符,32–127为可打印字符)。扩展ASCII使用8位,共256个字符,增加了重音字母和符号。

Unicode was developed to support all the world’s writing systems. UTF-8, UTF-16 and UTF-32 are encoding forms. UTF-8 uses 1–4 bytes per character and is backward compatible with ASCII; it is widely used on the web.

Unicode被开发用于支持世界上所有书写系统。UTF-8、UTF-16和UTF-32是编码形式。UTF-8每个字符使用1–4个字节,并与ASCII向后兼容;在网络上广泛使用。

OCR candidates should know the ASCII codes for: space (32₁₀ / 20₁₆), ‘0’ (48₁₀ / 30₁₆), ‘A’ (65₁₀ / 41₁₆), ‘a’ (97₁₀ / 61₁₆).

OCR考生应知道以下字符的ASCII码:空格(32₁₀ / 20₁₆),’0′ (48₁₀ / 30₁₆),’A’ (65₁₀ / 41₁₆),’a’ (97₁₀ / 61₁₆)。


5. Bitmap Images | 位图图像

A bitmap image is a grid of pixels, each assigned a colour. The colour depth (bits per pixel) determines how many distinct colours can be represented: 2ⁿ for n bits. A 1-bit image has 2 colours (black/white); 8-bit gives 256 colours; 24-bit true colour uses 8 bits each for red, green, blue, yielding ~16.7 million colours.

位图图像是由像素网格组成,每个像素分配一种颜色。颜色深度(每像素位数)决定了可表示的不同颜色数量:n位可表示2ⁿ种颜色。1位图像有2种颜色(黑/白);8位给出256种颜色;24位真彩色为红、绿、蓝各用8位,产生约1670万种颜色。

Resolution is the number of pixels per unit (e.g. pixels per inch, PPI). Higher resolution gives finer detail but larger file size. The image file size (uncompressed) = width × height × colour depth bits. For a 300×200 pixel image at 24-bit: 300×200×24 = 1,440,000 bits = 180,000 bytes ≈ 176 KiB.

分辨率是每单位像素数(如每英寸像素数PPI)。分辨率越高,细节越精细,但文件越大。图像文件大小(未压缩) = 宽 × 高 × 颜色深度(位)。对于300×200像素的24位图像:300×200×24 = 1,440,000位 = 180,000字节 ≈ 176 KiB。

Metadata stores additional information such as width, height, colour depth, and geolocation. It increases file size but is necessary for rendering.

元数据存储附加信息,如宽度、高度、颜色深度和地理位置。它增加文件大小,但对渲染必不可少。


6. Vector Graphics | 矢量图形

Vector images are composed of geometric primitives (lines, curves, polygons) defined by mathematical formulas and properties: position, colour, fill, stroke, line width. They are resolution independent and scale without pixelation.

矢量图像由几何图元(线、曲线、多边形)组成,通过数学公式和属性定义:位置、颜色、填充、描边、线宽。它们与分辨率无关,缩放时不产生像素化。

A typical vector drawing list records objects and their attributes. Example: Circle (cx=50, cy=60, r=30, fill=red, stroke=black, width=2). File size is usually smaller than bitmaps for simple diagrams, but complex photographs become inefficient.

典型的矢量绘图列表记录对象及其属性。例如:圆形 (cx=50, cy=60, r=30, fill=红, stroke=黑, width=2)。对于简单图形,文件通常比位图小,但复杂照片则效率低下。

Comparing bitmaps and vectors: bitmaps are better for photographs; vectors are better for logos, fonts, and illustrations. OCR exams may ask you to choose the appropriate format for a given scenario.

比较位图与矢量:位图更适合照片;矢量更适合标志、字体和插图。OCR考试可能要求你为给定场景选择合适的格式。


7. Sound Representation | 声音表示

Sound is analogue; to store it digitally, we sample the amplitude at discrete intervals (sample rate, in Hz) and quantise each sample to a binary value (bit depth). The Nyquist theorem states that the sampling rate must be at least twice the highest frequency present to avoid aliasing.

声音是模拟的;为数字化存储,我们以离散间隔(采样率,单位Hz)对振幅进行采样,并将每个样本量化为二进制值(位深)。奈奎斯特定理指出,采样率必须至少是最高频率的两倍,以避免混叠。

Common quality standards: CD uses 44.1 kHz sample rate and 16-bit depth. Higher sample rate captures higher frequencies; greater bit depth reduces quantisation noise, giving a larger dynamic range.

常见质量标准:CD使用44.1 kHz采样率和16位深度。采样率越高,捕获的频率越高;位深越大,量化噪声越小,动态范围越大。

File size for uncompressed sound = sample rate × bit depth × duration in seconds × number of channels. A 1-minute stereo CD-quality recording: 44100 × 16 × 60 × 2 = 84,672,000 bits ≈ 10.1 MB.

未压缩声音的文件大小 = 采样率 × 位深 × 时长(秒) × 声道数。1分钟立体声CD质量录音:44100 × 16 × 60 × 2 = 84,672,000位 ≈ 10.1 MB。

Bit rate (kbps) = sample rate × bit depth × channels. This metric is often used for streaming.

比特率(kbps) = 采样率 × 位深 × 声道数。此度量常用于流媒体。


8. Compression: Lossless and Lossy | 压缩:无损与有损

Compression reduces file size for storage and transmission. Lossless compression exploits statistical redundancy to represent data more concisely; the original can be perfectly reconstructed. Run-length encoding (RLE) replaces consecutive identical values with (count, value). For example, AAABBBCCC → A3B3C3.

压缩可减小文件大小以利于存储与传输。无损压缩利用统计冗余更简洁地表示数据;原始数据可完美重建。行程长度编码(RLE)将连续相同值替换为(计数, 值)。例如,AAABBBCCC → A3B3C3。

Dictionary-based compression (LZ77, LZ78) replaces repeated phrases with references to a dictionary. Huffman coding assigns shorter bit codes to more frequent symbols. In OCR, you may be asked to explain these algorithms or apply a given coding tree.

基于字典的压缩(LZ77, LZ78)将对重复短语的引用替换为字典中的索引。霍夫曼编码为更频繁的符号分配更短的位码。在OCR中,你可能会被要求解释这些算法或应用给定的编码树。

Lossy compression removes perceptually less important information, and the original cannot be perfectly restored. JPEG for images uses discrete cosine transform (DCT) and quantisation to discard high-frequency colour details. MP3 for audio masks sounds below the hearing threshold (perceptual coding).

有损压缩去除感知上不太重要的信息,原始数据无法完美恢复。图像JPEG使用离散余弦变换(DCT)和量化丢弃高频颜色细节。音频MP3通过掩蔽效应将低于听觉阈值的声音去除(感知编码)。

Compare: lossless is suitable for text, executable files, and archival; lossy is suitable for photographs, music streaming, and video where some quality loss is acceptable.

比较:无损适用于文本、可执行文件和档案;有损适用于照片、音乐流媒体和视频,在这些情境下一定的质量损失是可接受的。


9. Data Storage Units and File Size Calculation | 数据存储单位与文件大小计算

Bit (b) is the smallest unit. Nibble = 4 bits. Byte (B) = 8 bits. Kilobyte (kB) historically could be 1000 bytes or 1024 bytes; OCR uses the binary prefixes: kibibyte (KiB) = 1024 B, mebibyte (MiB) = 1024 KiB, gibibyte (GiB) = 1024 MiB. However, in file size calculations, candidates should follow the question’s instruction (powers of 10 or powers of 2).

位(b)是最小单位。半字节 = 4位。字节(B) = 8位。千字节(kB)历史上有1000字节或1024字节两种含义;OCR使用二进制前缀:kibibyte (KiB) = 1024 B, mebibyte (MiB) = 1024 KiB, gibibyte (GiB) = 1024 MiB。但在文件大小计算中,考生应遵循题目的指示(10的幂或2的幂)。

Be comfortable converting between bits, bytes and higher units. Practise calculations like: number of 500 kB images that can fit on a 4.7 GB DVD (using appropriate unit conversions).

要熟练掌握位、字节及更大单位之间的转换。练习如下计算:一张4.7 GB的DVD可容纳多少张500 kB的图像(使用适当的单位换算)。


10. Checksums and Parity for Error Detection | 校验和与奇偶校验的错误检测

When data is transferred, errors can occur. Parity bits add an extra bit to a byte so the total number of 1s is even (even parity) or odd (odd parity). This can detect single-bit errors but not two-bit errors.

数据传输时可能发生错误。奇偶校验位给字节增加一个额外位,使1的总数为偶数(偶校验)或奇数(奇校验)。这可以检测单比特错误,但不能检测两比特错误。

Majority voting: each bit is sent three times; the receiver takes the majority value. This can correct single errors but triples the data volume.

多数表决:每个比特发送三次;接收方取多数的值。这能纠正单比特错误,但将数据量增至三倍。

Checksums: a numeric value calculated from the data block (e.g. sum of bytes, modulo 256) is appended. The receiver recalculates and compares. Simple checksums may miss some errors; cyclic redundancy checks (CRC) are more robust and are based on polynomial division.

校验和:从数据块计算出的数值(如字节和,取模256)被附加到尾部。接收方重新计算并比较。简单校验和可能漏检某些错误;循环冗余校验(CRC)更稳健,基于多项式除法实现。

Check digits for human-readable codes (ISBN, barcodes) often use modular arithmetic. For example, ISBN-10 multiplies digits by weights 10 down to 1, sums them, and the check digit makes the sum divisible by 11.

用于人类可读代码(ISBN、条形码)的校验位通常使用模运算。例如,ISBN-10将数字乘以从10递减至1的权重,求和后校验位使总和能被11整除。


11. Practical Exam Tips for OCR Data Representation | OCR数据表示实战技巧

Show your working clearly in calculations. Convert numbers step by step, marking the place values. When adding binary, write carry bits above the columns. For floating point, draw mantissa and exponent boxes to avoid misalignment.

计算时要清晰展示步骤。逐步转换数字,标出位权。二进制加法时,在列上方写出进位。浮点部分,画出尾数和阶码框以避免对齐错误。

Watch out for typical OCR pitfalls: forgetting to normalise, confusing two’s complement subtraction with addition, misinterpreting the range of exponent values, mixing up KiB and kB, and ignoring metadata when calculating file size.

注意OCR常见陷阱:忘记规格化,混淆补码减法和加法,误解指数值的范围,混淆KiB与kB,以及在计算文件大小时忽略元数据。

If asked to compare compression methods, use examples: RLE works well on simple graphics with long runs; Huffman is efficient for text with skewed character frequencies; lossy JPEG is ideal for photographs. Link your reasoning to the scenario given.

若要求比较压缩方法,用实例说明:RLE适用于长行程的简单图形;霍夫曼编码适用于字符频率分布不均的文本;有损JPEG是照片的理想之选。将推理与所给场景联系起来。

Stay familiar with standard ASCII codes and the pattern: uppercase letters start at 65, lowercase at 97, digits at 48.

熟悉标准ASCII码和规律:大写字母从65开始,小写从97开始,数字从48开始。


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