Data Representation and Number Systems | 数据表示与数制

📚 Data Representation and Number Systems | 数据表示与数制

All digital data, whether text, images, or sound, is ultimately stored and processed as sequences of 0s and 1s. Understanding how numbers are represented in binary and hexadecimal is fundamental to grasping how computers work at the lowest level. This article covers the core concepts from the Cambridge IGCSE Computer Science course, including conversion techniques, binary arithmetic, and the role of hexadecimal in simplifying binary for human readability.

所有数字数据,无论是文本、图像还是声音,最终都以 0 和 1 的序列存储和处理。理解数字如何以二进制和十六进制表示,是掌握计算机底层工作原理的基础。本文涵盖了剑桥 IGCSE 计算机科学课程的核心概念,包括转换技术、二进制算术,以及十六进制在简化二进制以便人类阅读方面的作用。

1. Why Computers Use Binary | 为什么计算机使用二进制

Computers are built from billions of tiny switches called transistors, which can only be in one of two states: on (1) or off (0). This two-state system maps perfectly onto the binary number system, which uses only the digits 0 and 1. All forms of data — numbers, characters, instructions — are encoded as combinations of these binary digits (bits).

计算机由数十亿个称为晶体管的微型开关组成,这些开关只能处于两种状态之一:开(1)或关(0)。这种双态系统完美地映射到二进制数系统,该系统仅使用数字 0 和 1。所有形式的数据——数字、字符、指令——都被编码为这些二进制位(比特)的组合。

2. The Denary (Decimal) System | 十进制系统

Humans typically count in denary, or base 10, because we have ten fingers. In denary, the value of a digit depends on its place: units, tens, hundreds, etc. Each place is a power of 10. For example, 307 = (3 × 100) + (0 × 10) + (7 × 1). This understanding of place value is essential before converting to other bases.

人类通常以十进制(基数为 10)计数,因为我们有十个手指。在十进制中,数字的值取决于它的位置:个位、十位、百位等。每个位置都是 10 的幂。例如,307 = (3 × 100) + (0 × 10) + (7 × 1)。在转换到其他进制之前,理解这种位值概念至关重要。

3. The Binary Number System | 二进制数系统

Binary is base 2, using only digits 0 and 1. The place values are powers of 2: 1, 2, 4, 8, 16, 32, 64, 128, and so on, increasing from right to left. An 8-bit binary number is called a byte and can represent denary values from 0 to 255. For example, the binary number 10110011 represents (1×128) + (0×64) + (1×32) + (1×16) + (0×8) + (0×4) + (1×2) + (1×1) = 179 in denary.

二进制是基数为 2 的系统,仅使用数字 0 和 1。位值是 2 的幂:1、2、4、8、16、32、64、128 等,从右向左递增。一个 8 位二进制数称为一个字节,可以表示 0 到 255 的十进制值。例如,二进制数 10110011 表示 (1×128) + (0×64) + (1×32) + (1×16) + (0×8) + (0×4) + (1×2) + (1×1) = 179(十进制)。

4. Converting Denary to Binary | 十进制转二进制

To convert a denary number into binary, repeatedly divide the number by 2, recording the remainder each time. The remainders read from bottom to top (or last to first) give the binary equivalent. Alternatively, use the subtraction method: compare the denary number to descending powers of 2 and place a 1 if the power fits, subtracting the value.

要将十进制数转换为二进制,反复将该数除以 2,每次记录余数。从底向上(或从最后到最先)读取余数,即得二进制。另一种方法是减法:将十进制数与递减的 2 的幂进行比较,如果该幂适合,则放 1,并减去该值。

Example: Convert 53 to binary

Division method: 53 ÷ 2 = 26 r1; 26 ÷ 2 = 13 r0; 13 ÷ 2 = 6 r1; 6 ÷ 2 = 3 r0; 3 ÷ 2 = 1 r1; 1 ÷ 2 = 0 r1. Reading remainders upwards: 110101. So 53 in binary is 00110101 (8-bit).

示例:将 53 转换为二进制

除法:53 ÷ 2 = 26 余1;26 ÷ 2 = 13 余0;13 ÷ 2 = 6 余1;6 ÷ 2 = 3 余0;3 ÷ 2 = 1 余1;1 ÷ 2 = 0 余1。向上读取余数:110101。所以 53 的二进制为 00110101(8 位)。


5. Binary Addition and Overflow | 二进制加法与溢出

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. When adding two binary numbers, you may get a result that requires more bits than allowed. An overflow error occurs when a calculation produces a value that exceeds the maximum representable number for the given number of bits. For instance, adding 11111111 (255) and 00000001 (1) in 8-bit registers results in 1 00000000 (256), but the 8-bit result is 00000000 with a carry out, flagging an overflow.

二进制加法遵循简单规则:0+0=0,0+1=1,1+0=1,1+1=0 进1,以及 1+1+进位=1 进1。当两个二进制数相加时,可能得到需要比允许位数更多位的结果。当计算结果超出给定位数可表示的最大值时,就会发生溢出错误。例如,在 8 位寄存器中将 11111111(255)和 00000001(1)相加,结果是 1 00000000(256),但 8 位结果为 00000000,并有一个进位输出,标记溢出。

6. Logical Binary Shifts | 逻辑二进制移位

A logical shift moves all bits in a binary number left or right by a certain number of positions. Vacated positions are filled with zeros. A left shift of one place multiplies the number by 2; a right shift divides by 2 (ignoring remainders for whole-number arithmetic). For example, shifting 00001100 (12) left once gives 00011000 (24). Multiple shifts multiply or divide by powers of 2, but beware of losing 1s shifted out and causing overflow.

逻辑移位将二进制数中的所有位向左或向右移动指定数量的位置。空出的位置用零填充。左移一位将数乘以 2;右移一位则除以 2(整数运算忽略余数)。例如,将 00001100(12)左移一位得到 00011000(24)。多次移位即乘以或除以 2 的幂,但要小心丢失移出的 1 和引起溢出。

7. Introducing the Hexadecimal System | 十六进制系统简介

Hexadecimal (hex) is base 16, using digits 0–9 and letters A–F to represent values 10 to 15. It is widely used in computing because it provides a more compact and human-friendly way to display binary values. One hex digit represents exactly 4 bits (a nibble), so an 8-bit byte can be shown as two hex digits. For example, 11111111 in binary is FF in hex.

十六进制是基数为 16 的系统,使用数字 0–9 和字母 A–F 表示值 10 到 15。它在计算中广泛使用,因为它提供了一种更紧凑且更易于人类阅读的方式来显示二进制值。一个十六进制数字正好代表 4 位(一个半字节),所以一个 8 位字节可以显示为两个十六进制数字。例如,二进制 11111111 在十六进制中为 FF。

Denary Binary (4-bit) Hex
0 0000 0
1 0001 1
10 1010 A
15 1111 F

8. Converting Binary to Hexadecimal and Vice Versa | 二进制与十六进制互转

To convert binary to hex, group the binary digits into sets of four (nibbles) starting from the right. Add leading zeros to the leftmost group if needed. Then convert each 4-bit group into the equivalent hex digit using the table. For example, 11010111 becomes 1101 0111, which is D7 (since 1101 = D, 0111 = 7). To convert hex to binary, simply replace each hex digit with its 4-bit binary equivalent.

要将二进制转换为十六进制,从右开始将二进制数字分成四位一组(半字节)。如果需要,在最左组前补零。然后使用表格将每个 4 位组转换为对应的十六进制数字。例如,11010111 变成 1101 0111,即 D7(因为 1101 = D,0111 = 7)。要将十六进制转换为二进制,只需将每个十六进制数字替换为其对应的 4 位二进制。

9. Converting Denary to Hexadecimal | 十进制转十六进制

One method is to convert denary to binary first, then binary to hex. Alternatively, you can use repeated division by 16. Divide the denary number by 16, noting the remainder; convert remainders greater than 9 into hex letters. Continue until the quotient is 0, then read remainders in reverse order. For example, 200 ÷ 16 = 12 remainder 8, and 12 ÷ 16 = 0 remainder 12 (C). Thus 200 = C8 in hex.

一种方法是先将十进制转换为二进制,再将二进制转换为十六进制。或者,可以使用反复除以 16 的方法。将十进制数除以 16,记下余数;将大于 9 的余数转换为十六进制字母。继续直到商为 0,然后倒序读取余数。例如,200 ÷ 16 = 12 余 8,12 ÷ 16 = 0 余 12 (C)。因此 200 的十六进制为 C8。

10. Uses of Hexadecimal in Computing | 十六进制在计算机中的用途

Hexadecimal is used to represent machine code and memory addresses because it is shorter and less prone to error than long binary strings. Colour codes in HTML and CSS use hex (e.g., #FF5733), where each pair of hex digits represents the intensity of red, green, and blue. MAC addresses and assembly language also frequently employ hex. Error codes are often displayed in hexadecimal to make them easier to interpret.

十六进制用于表示机器码和内存地址,因为它比长二进制串更短且不易出错。HTML 和 CSS 中的颜色代码使用十六进制(例如 #FF5733),其中每对十六进制数字代表红、绿、蓝的强度。MAC 地址和汇编语言也经常使用十六进制。错误代码通常以十六进制显示,以便于解读。

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

Characters are represented in binary using standard codes. ASCII uses 7 bits to represent 128 characters, including letters, digits, and control characters. Extended ASCII uses 8 bits for 256 characters, including accented letters and symbols. Unicode was developed to cover characters from many writing systems worldwide, using up to 32 bits per character. UTF-8 is a variable-length encoding that is backward-compatible with ASCII.

字符使用标准代码以二进制表示。ASCII 使用 7 位表示 128 个字符,包括字母、数字和控制字符。扩展 ASCII 使用 8 位表示 256 个字符,包含重音字母和符号。Unicode 的开发是为了覆盖全球多种书写系统的字符,每个字符最多使用 32 位。UTF-8 是一种与 ASCII 向后兼容的变长编码。

Character Denary Binary (7-bit) Hex
A 65 1000001 41
a 97 1100001 61
0 48 0110000 30

12. Representing Images and Sound | 图像与声音的表示

Images are represented as a grid of pixels. Colour depth (bits per pixel) determines the number of available colours. For example, 8-bit colour depth gives 2⁸ = 256 colours. Resolution is the number of pixels (e.g., 1920×1080). Sound is represented by sampling the amplitude of the sound wave at regular intervals. Sampling rate (in Hz) and bit depth determine the quality and file size. Higher sampling rates and bit depths improve quality but increase storage needs.

图像表示为像素网格。色彩深度(每像素位数)决定了可用颜色的数量。例如,8 位色彩深度提供 2⁸ = 256 种颜色。分辨率是像素数(例如 1920×1080)。声音通过定期对声波振幅进行采样来表示。采样率(赫兹)和位深度决定了质量和文件大小。更高的采样率和位深度可提高质量,但会增加存储需求。

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