Binary Representation of Text, Sound and Images | 文本、声音和图像的二进制编码原理

📚 Binary Representation of Text, Sound and Images | 文本、声音和图像的二进制编码原理

Computers are digital devices that process information in the form of binary digits (bits). Every piece of data — whether it is a word document, a music file, or a photograph — must ultimately be converted into sequences of 0s and 1s before it can be stored or processed. This article explores how text, sound, and images are encoded in binary, covering the key principles required for the CIE A-Level Computer Science syllabus.

计算机是数字设备,所有信息都以二进制数字(位)的形式处理。无论是文字文档、音乐文件还是照片,任何数据最终都必须转换为由 0 和 1 组成的序列,才能被存储或处理。本文将探讨文本、声音和图像如何以二进制编码,涵盖 CIE A-Level 计算机科学考纲中的核心原理。


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

Binary representation uses only two states: 0 and 1. In electronic circuits, these two states correspond to two distinct voltage levels — for example, 0 V representing 0 and 5 V representing 1. This simplicity makes digital circuits reliable, because distinguishing between two voltage levels is far easier than distinguishing among ten different levels (as would be needed for decimal representation).

二进制表示只使用两种状态:0 和 1。在电子电路中,这两种状态对应两个不同的电压电平——例如,0 V 表示 0,5 V 表示 1。这种简单性使数字电路非常可靠,因为区分两个电压电平远比区分十个不同电平(如果采用十进制表示则需要)容易得多。

Each binary digit is called a bit. Eight bits form one byte, which is the fundamental unit of storage in most computer systems. A bit can represent 2¹ = 2 values, two bits represent 2² = 4 values, and in general, n bits can represent 2ⁿ distinct values.

每一位二进制数字称为一个比特(bit)。八个比特组成一个字节(byte),字节是大多数计算机系统中基本的存储单位。一个比特可以表示 2¹ = 2 种值,两个比特表示 2² = 4 种值,一般地,n 个比特可以表示 2ⁿ 种不同的值。


2. Text Encoding: Character Sets | 文本编码:字符集

Text is stored in a computer by assigning a unique binary code to each character. The set of characters that a computer can represent, along with the codes assigned to them, is called a character set. Each character — whether a letter, digit, punctuation mark, or control symbol — is mapped to a specific binary pattern.

文本在计算机中的存储方式是为每个字符分配一个唯一的二进制码。计算机能够表示的字符集合,连同分配给它们的编码,称为字符集。每个字符——无论是字母、数字、标点符号还是控制符号——都被映射到一个特定的二进制模式。

  • Character set: the complete collection of characters supported by an encoding system.
  • Code point: the numerical value assigned to a character within the character set.
  • Encoding scheme: the rules for converting code points into binary sequences.

字符集:一种编码系统所支持的全部字符的集合。

码点:字符集中分配给某个字符的数值。

编码方案:将码点转换为二进制序列的规则。

The choice of character set determines how many different characters can be represented. A character set using 7 bits can represent 2⁷ = 128 characters, while an 8-bit set can represent 2⁸ = 256 characters.

字符集的选择决定了能够表示多少个不同的字符。使用 7 位的字符集可以表示 2⁷ = 128 个字符,而 8 位字符集可以表示 2⁸ = 256 个字符。


3. ASCII Encoding | ASCII 编码

The American Standard Code for Information Interchange (ASCII) is one of the earliest and most widely used character sets. The basic ASCII set uses 7 bits per character, providing 128 unique codes (0 to 127). These include:

美国信息交换标准码(ASCII)是最早且应用最广泛的字符集之一。基本 ASCII 集每个字符使用 7 位,提供 128 个唯一编码(0 至 127)。其中包括:

  • Uppercase letters A–Z: codes 65–90
  • Lowercase letters a–z: codes 97–122
  • Digits 0–9: codes 48–57
  • Punctuation and symbols: e.g., space = 32, ‘!’ = 33
  • Control characters: e.g., null = 0, line feed = 10

大写字母 A–Z:编码 65–90

小写字母 a–z:编码 97–122

数字 0–9:编码 48–57

标点与符号:例如空格 = 32,’!’ = 33

控制字符:例如空字符 = 0,换行 = 10

For example, the uppercase letter ‘A’ has ASCII code 65. Converting 65 to binary gives 1000001 (7 bits). To store ASCII data in bytes, the eighth bit is sometimes used as a parity bit for error checking, or set to 0. The extended ASCII set uses all 8 bits, providing 256 characters, which allows additional symbols such as accented letters and box-drawing characters.

例如,大写字母 ‘A’ 的 ASCII 码为 65。将 65 转换为二进制得到 1000001(7 位)。在将 ASCII 数据存储为字节时,第八位有时用作奇偶校验位以进行错误检测,或设置为 0。扩展 ASCII 集使用全部 8 位,提供 256 个字符,可以表示带重音字母和制表符等附加符号。

Character | 字符 ASCII Code (Decimal) | 十进制 Binary (7-bit) | 二进制(7位)
A 65 1000001
B 66 1000010
a 97 1100001
0 (zero) 48 0110000

4. Unicode: Representing All Languages | Unicode:表示所有语言

ASCII has a major limitation: it cannot represent characters from non-Latin scripts such as Chinese, Japanese, Arabic, or emoji. To solve this problem, Unicode was developed as a universal character set that aims to encode every character used in all human writing systems.

ASCII 有一个重大局限性:它无法表示拉丁字母以外的字符,如中文、日文、阿拉伯文或表情符号。为解决这一问题,Unicode 被开发为一种通用字符集,旨在为所有人类书写系统中的每个字符提供编码。

Unicode assigns each character a unique code point, written in hexadecimal notation such as U+0041 for ‘A’ and U+4E2D for the Chinese character ‘中’. However, Unicode code points must be converted to binary for storage. The most common encoding schemes are:

Unicode 为每个字符分配一个唯一的码点,以十六进制表示法书写,例如 U+0041 表示 ‘A’,U+4E2D 表示汉字 ‘中’。然而,Unicode 码点必须转换为二进制才能存储。最常见的编码方案有:

  • UTF-8: variable-length encoding using 1 to 4 bytes per character. ASCII characters occupy 1 byte, so ASCII text is identical in UTF-8.
  • UTF-16: uses 2 or 4 bytes per character. More efficient for scripts that require many non-ASCII characters.

UTF-8:可变长度编码,每个字符使用 1 至 4 个字节。ASCII 字符占 1 个字节,因此 ASCII 文本在 UTF-8 中与原编码相同。

UTF-16:每个字符使用 2 或 4 个字节。对于需要大量非 ASCII 字符的文字系统更为高效。

UTF-8 has become the dominant encoding for the web because it is backward-compatible with ASCII and efficient for English text. For example, the character ‘中’ (U+4E2D) is encoded as three bytes in UTF-8: E4 B8 AD, whereas ‘A’ is stored as a single byte: 0x41.

UTF-8 已成为网页的主流编码,因为它与 ASCII 向后兼容且对英文文本高效。例如,字符 ‘中’(U+4E2D)在 UTF-8 中编码为三个字节:E4 B8 AD,而 ‘A’ 存储为单个字节:0x41。


5. Sound Encoding: Analogue to Digital | 声音编码:从模拟到数字

Sound is a continuous (analogue) wave that varies in amplitude and frequency over time. To store sound on a computer, this continuous wave must be converted into discrete binary values — a process called analogue-to-digital conversion (ADC).

声音是一种连续(模拟)波,其振幅和频率随时间变化。要在计算机上存储声音,需要将该连续波转换为离散的二进制值——这一过程称为模数转换(ADC)

The two key parameters in sound digitisation are the sampling rate and the bit depth (also called sample resolution). The ADC device, often built into a sound card, performs the conversion. The resulting digital signal can then be stored as a sequence of numbers, each representing the amplitude of the wave at a particular instant.

声音数字化的两个关键参数是采样率位深度(也称为采样分辨率)。ADC 设备通常内置于声卡中,负责执行转换。生成的数字信号可以存储为一系列数字,每个数字代表波在某一特定时刻的振幅。


6. Sampling Rate and Bit Depth | 采样率与位深度

The sampling rate (measured in Hz) is the number of times per second that the analogue wave is measured. For example, a sampling rate of 44.1 kHz means the amplitude is recorded 44,100 times per second — the standard used for audio CDs. According to the Nyquist theorem, the sampling rate must be at least twice the highest frequency present in the signal to reproduce it accurately.

采样率(以 Hz 为单位)是每秒对模拟波进行测量的次数。例如,44.1 kHz 的采样率意味着每秒记录振幅 44,100 次——这是音频 CD 使用的标准。根据奈奎斯特定理,采样率必须至少是信号中最高频率的两倍,才能准确重现原始信号。

The bit depth determines how many different amplitude levels can be represented. A bit depth of 16 bits allows 2¹⁶ = 65,536 possible amplitude values. Higher bit depth means finer amplitude resolution and therefore the recorded sound has a wider dynamic range, but it also produces larger file sizes.

位深度决定了可以表示多少种不同的振幅电平。16 位的位深度允许 2¹⁶ = 65,536 种可能的振幅值。位深度越高,振幅分辨率越精细,因此录制声音的动态范围更宽,但文件体积也更大。

Sound file size (bits) = sample rate × bit depth × duration × number of channels

声音文件大小(比特)= 采样率 × 位深度 × 时长 × 声道数

For example, a 3-second stereo (2-channel) recording with a sample rate of 44,100 Hz and 16-bit depth has a size of:

例如,一段 3 秒的立体声(双声道)录音,采样率为 44,100 Hz,位深度为 16 位,其大小为:

44,100 × 16 × 3 × 2 = 4,233,600 bits = 529,200 bytes ≈ 517 KB

44,100 × 16 × 3 × 2 = 4,233,600 比特 = 529,200 字节 ≈ 517 KB


7. Image Encoding: Pixels and Resolution | 图像编码:像素与分辨率

A digital image is composed of a grid of tiny squares called pixels (picture elements). Each pixel stores the colour and intensity of that point in the image. The resolution of an image is the number of pixels in each dimension, usually expressed as width × height, for example 1920 × 1080.

数字图像由称为像素(图像元素)的微小方格网格组成。每个像素存储该点在图像中的颜色和亮度。分辨率是图像在每个维度上的像素数量,通常表示为宽 × 高,例如 1920 × 1080。

The total number of pixels in an image is calculated by multiplying the width by the height:

图像的总像素数通过将宽度乘以高度来计算:

Total pixels = width × height

总像素数 = 宽 × 高

A higher resolution image contains more pixels, allowing finer detail to be captured. However, more pixels also mean the image file requires more storage space. For instance, an 800 × 600 image contains 480,000 pixels, while a 1920 × 1080 image contains 2,073,600 pixels — more than four times as many.

分辨率越高的图像包含的像素越多,能够捕捉到更精细的细节。然而,像素越多也意味着图像文件需要更多的存储空间。例如,800 × 600 的图像包含 480,000 个像素,而 1920 × 1080 的图像包含 2,073,600 个像素——是前者的四倍多。


8. Colour Depth | 颜色深度

The colour depth (also called bit depth for images) specifies how many bits are used to represent the colour of each pixel. With n bits per pixel, an image can display 2ⁿ distinct colours.

颜色深度(对于图像也称为位深度)指定了每个像素用多少比特来表示颜色。每个像素使用 n 位,图像就能显示 2ⁿ 种不同的颜色。

  • 1-bit colour depth: 2¹ = 2 colours (typically black and white)
  • 8-bit colour depth: 2⁸ = 256 colours
  • 24-bit colour depth: 2²⁴ = 16,777,216 colours (true colour, 8 bits per RGB channel)

1 位颜色深度:2¹ = 2 种颜色(通常为黑白)

8 位颜色深度:2⁸ = 256 种颜色

24 位颜色深度:2²⁴ = 16,777,216 种颜色(真彩色,每个 RGB 通道 8 位)

In the 24-bit true colour system, each pixel stores three 8-bit values representing the intensity of red, green, and blue (RGB). For example, pure red is represented as R=255, G=0, B=0, and pure white is R=255, G=255, B=255. In binary, the value 255 is 11111111.

在 24 位真彩色系统中,每个像素存储三个 8 位值,分别代表红、绿、蓝(RGB)的强度。例如,纯红色表示为 R=255、G=0、B=0,纯白色为 R=255、G=255、B=255。在二进制中,值 255 为 11111111。

Image file size (bits) = width × height × colour depth

图像文件大小(比特)= 宽 × 高 × 颜色深度

For a 1000 × 800 image with 24-bit colour depth:

对于一幅 1000 × 800、颜色深度为 24 位的图像:

1000 × 800 × 24 = 19,200,000 bits = 2,400,000 bytes ≈ 2.29 MB

1000 × 800 × 24 = 19,200,000 比特 = 2,400,000 字节 ≈ 2.29 MB


9. Bitmap vs Vector Graphics | 位图与矢量图形

There are two fundamentally different ways to store images digitally. Bitmap (raster) images store each pixel individually, as described above. They are excellent for photographs because they capture fine colour gradients, but they scale poorly — enlarging a bitmap image causes pixelation (visible blocky artefacts).

数字图像有两种根本不同的存储方式。位图(栅格)图像逐像素存储,如前所述。位图非常适合照片,因为它能捕捉细腻的颜色渐变,但缩放效果不佳——放大位图图像会导致像素化(出现明显的块状伪影)。

Vector graphics, in contrast, store images as mathematical descriptions of shapes — lines, curves, circles, and polygons. Each shape is defined by coordinates and attributes such as stroke colour and fill colour. Vector images can be scaled infinitely without losing quality because the computer recalculates the shapes at any size. However, vector graphics are poorly suited for complex natural scenes like photographs.

矢量图形则不同,它以数学描述的方式存储图像——线、曲线、圆和多边形。每个形状由坐标和属性(如描边颜色、填充颜色)定义。矢量图像可以无限缩放而不损失质量,因为计算机会在任何尺寸下重新计算形状。然而,矢量图形不适合表示照片这类复杂的自然场景。

Feature | 特性 Bitmap | 位图 Vector | 矢量
Storage method | 存储方式 Pixel values | 像素值 Mathematical shapes | 数学形状
Scaling | 缩放 Loses quality | 损失质量 No quality loss | 无质量损失
Best for | 适用场景 Photographs | 照片 Logos, diagrams | 标志、图表

10. Binary Encoding: Advantages and Limitations | 二进制编码的优势与局限

Encoding all forms of data in binary offers several important advantages. Digital data is robust to noise — minor voltage fluctuations do not corrupt a 0 or a 1 as long as the level remains within the valid range. Binary data can be stored reliably on various media (magnetic, optical, solid-state) and transmitted over networks with error detection and correction techniques.

将各种形式的数据编码为二进制带来了几个重要优势。数字数据对噪声具有鲁棒性——只要电压电平保持在有效范围内,轻微的电压波动不会破坏 0 或 1。二进制数据可以可靠地存储在各种介质(磁、光、固态)上,并可通过网络传输,配合错误检测与纠正技术使用。

There are also trade-offs to consider. Higher fidelity in text (Unicode), sound (higher sample rate/bit depth), and images (higher resolution/colour depth) always requires larger file sizes. This creates a constant tension between quality and storage capacity. Consequently, compression algorithms — such as JPEG for images and MP3 for audio — are often applied to reduce file sizes, typically at the cost of some quality in lossy compression (or losslessly, where no data is lost but the compression ratio is lower).

同时也存在需要权衡的地方。文本(Unicode)、声音(更高的采样率/位深度)和图像(更高的分辨率/颜色深度)的保真度越高,文件体积就越大。这在质量与存储容量之间产生了持续的张力。因此,压缩算法——如图像的 JPEG 和音频的 MP3——常被用来减小文件大小,但在有损压缩中通常以牺牲部分质量为代价(无损压缩则不会丢失数据,但压缩比相对较低)。

Understanding the binary encoding of text, sound, and images is essential for computing, as it explains how raw data is transformed into digital form and why storage requirements scale with fidelity. These principles underpin everything from streaming video to cloud document storage.

理解文本、声音和图像的二进制编码是计算机科学的基础,它解释了原始数据如何转化为数字形式,以及为什么存储需求随保真度呈比例增长。这些原理支撑着从视频流媒体到云端文档存储的一切应用。


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课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply

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

Exit mobile version