说明
本文是个人学习用的非官方中英对照译文,原文:https://diveintosystems.org/book/C4-Binary/summary.html。
原书采用 CC BY-NC-ND 4.0 许可(禁止演绎),请勿公开传播本译文。
标为「译注」「现代更新」的内容是译者补充,不代表原书作者观点;代码与原文逐字一致,未作改动。
4.9. Summary
本章考察了现代计算机如何用位和字节表示信息。一个重要的结论是:计算机的内存把所有信息都存储为二进制的 0 和 1——这些位的含义由程序或运行程序的人来解释。本章主要关注整数的表示,先介绍了无符号(非负)整数,然后考虑了有符号整数。
This chapter examined how modern computers represent information using bits and bytes. An important takeaway is that a computer’s memory stores all information as binary 0’s and 1’s — it’s up to programs or the people running them to interpret the meaning of those bits. This chapter primarily focused on integer representations, beginning with unsigned (non-negative) integers before considering signed integers.
计算机硬件支持对整数进行多种运算,包括熟悉的加、减、乘、除。系统还提供按位与、按位或、按位取反和移位等位运算。在进行任何运算时,都要考虑表示操作数和结果所用的位数。如果为结果分配的存储空间不够大,溢出就可能让结果的值失真。
Computer hardware supports a variety of operations on integers, including the familiar addition, subtraction, multiplication, and division. Systems also provide bitwise operations like bitwise AND, OR, NOT, and shifting. When performing any operation, consider the number of bits used to represent the operands and result. If the storage space allocated to the result isn’t large enough, an overflow may misrepresent the resulting value.
最后,本章探讨了在二进制中表示实数的常见方案,包括标准的 IEEE 754 标准。注意,在表示浮点值时,我们以牺牲精度为代价换取了更大的灵活性(即移动小数点的能力)。
Finally, this chapter explored common schemes for representing real numbers in binary, including the standard IEEE 754 standard. Note that when representing floating-point values, we sacrifice precision for increased flexibility (i.e., the ability to move the decimal point).