YP2.1 Bits and Data Types (双语)

from:

[1] Introduction to Computing System, from Bits and Gates to C and Beyond. Yale N. Patt and Sanjay J. Patel. McGraw-Hill Higher Education.(英)

[2] 计算系统基础_陈道蓄http://course.jingpinke.com/details?uuid=8a833999-2031c13b-0120-31c13bb1-012b

2.1 Bits and Data Types

2.1.1 The Bit as the Unit of Information

We noted in Chapter 1 that the computer was organized as a system with several levels oftransformation. A problem stated in a natural language such as English is actually solved by the electrons moving around inside the electronics of the computer.

Inside the computer, millions of very tiny, very fast devices control the movement of those electrons. These devices react to the presence or absence of voltages in electronic circuits. They could react to the actual voltages, rather than simply to the presence or absence of voltages. However, this would make the control and detection circuits more complex than they need to be. It is much easier simply to detect whether or not a voltage exists between a pair of points in a circuit than it is to measure exactly what that voltage is.

To understand this, consider any wall outlet in your home. You could measure the exact voltage it is carrying, whether 120 volts or 115 volts, or 118.6 volts, for example. However, the detection circuitry to determineonlywhether there is a voltage (any of the above three will do) or whether there is no voltage is much simpler. Your finger casually inserted into the wall socket, for example, will suffice.

We symbolically represent the presence of a voltage as "1" and the absence of a voltage as "0." We refer to each 0 and each 1 as a "bit," which is a shortened form of binary digit. Recall the digits you have been using since you were a child—0, 1, 2, 3 , . . . , 9. There are 10 of them, and they are referred to as decimal digits. In the case of binary digits, there are two of them, 0 and 1.

To be perfectly precise, it is not really the case that the computer differentiates theabsolute absence of a voltage (that is, 0) from theabsolute presence of a voltage (that is, 1). Actually, the electronic circuits in the computer differentiate voltages close to0 from voltagesfar from0. So, for example, if the computer expects a voltage of 2.9 volts or a voltage of 0 volts (2.9 volts signifying 1 and 0 volts signifying 0), then a voltage of 2.6 volts will be taken as a 1 and 0.2 volts will be taken as a 0.

To get useful work done by the computer, it is necessary to be able to identify uniquely a large number of distinct values. The voltage on one wire can represent uniquely one of only two things. One thing can be represented by 0, the other thing can be represented by 1. Thus, to identify uniquely many things, it is necessary to combine multiple bits. For example, if we use eight bits (corresponding to the voltage present on eight wires), we can represent one particular value as 01001110, and another value as 11100111. In fact, if we are limited to eight bits, we can differentiate at most only 256 (that is, 28) different values. In general, withkbits, we can distinguish at most2k distinct items. Each pattern of thesebits is a code; that is, it corresponds to a particular value.

2.1.2 Data Types

There are many ways to represent the same value. For example, the number five can be written as a 5. This is the standard decimal notation that you are used to. The value five can also be represented by someone holding up one hand, with all fingers and thumb extended. The person is saying, "The number I wish to communicate can be determined by counting the number of fingers I am showing." A written version of that scheme would be the value 11111. This notation has a name also—unary. The Romans had yet another notation for five—the character V. We will see momentarily that a fourth notation for five is the binary representation 00000101.

It is not enough simply to represent values; we must be able to operate on those values. We say a particular representation is adata type if there are operations in the computer that can operate on information that is encoded in that representation. Each ISA has its own set of data types and its own set of instructions that can operate on those data types. In this book, we will mainly use two data types: 2'scomplement integers for representing positive and negative integers that we wish to perform arithmetic on, andASCII codes for representing characters on the keyboard that we wish to input to a computer or display on the computer's monitor. Both data types will be explained shortly.

There are other representations of information that could be used, and indeed that are present in most computers. Recall the "scientific notation" from high school chemistry where you were admonished to represent the decimal number 621 as 6.21*102. There are computers that represent numbers in that form, and they provide operations that can operate on numbers so represented. That data type is usually calledfloating point.We will show you its representation in Section 2.6.

2.1 比特和数据类型

2.1.1 信息的最小单位——比特

我们在第一章中提到,计算机是一个由多个层次组织起来的系统。在计算机中通过电子的流动,一个用自然语言描述的问题可以轻而易举的得到解决。

在计算机的内部,数以亿计非常微小、快速的元件控制着电子的流动。这些元件对电路中电压的有无做出反应。事实上,它们可以对电压具体的数值做出反应,而不仅仅是对电压的有无做出反应。但是这样会使控制电路和探测电路变得非常复杂而没有多少实际用途,因此在实际的应用中往往是探测两点之间电压的有无而不是测量电压的具体值。

要明白这些,先想一想家中的插座孔,你可以测量一下两孔间电压具体的值,比如,是120伏特呢,还是115伏特,或者是118.6伏特。但是电路系统只会探测电压是否存在,因为这样更简单。如果你想测量电压值,那么你还需要一组仪器,而如果想探测电压是否存在,把你的手指伸进去就足够了(开个玩笑)。

我们把存在电压用“1”表示,而把不存在电压用“0”表示,我们称这一个个的“0”和“1”为比特(bit),或,是二进制位”(binary digit)的缩写。想想你从小就使用的0,1,2,3,4,5,6,7,8,9,它们是十进制数,用十个符号表示,而二进制只有两个表示数的符号:0和1。

更精确的说,计算机并不是区分电压的绝对不存在(即0)和绝对存在(即1)。实际上,计算机的电路区分的是接近0的电压和远离0的电压。例如,如果计算机把2.9伏的电压表示为1,把0伏的电压表示为0,那么2.6伏的电压也会被视作1,而0.2伏的电压会被当作0。

计算机要解决一个真正的问题,必须能唯一的识别出许多不同的数值,而不仅仅是0和1。一根线路上的电压只能唯一的表示两个数值中的一个,一个表示为0,另一个表示为1。这样,为了唯一的识别出多个数值,必须对多个位进行组合。例如,如果我们用8位(对应8根线路上的电压),我们就能用01001110表示某一个特定值,用11100111表示另一个值。事实上,如果我们使用8位,最多能区分出256(即28)个不同的值。一般说来,如果有k位,我们最多能区分出2k个不同的值。这些k位的每一种组合都是一个编码,对应着某个特定的值。

2.1.2 数据类型

对于表示同一个数值,存在许多种表示方法。例如,数字5可以被写为5。这是你习惯的标准的十进制计数法。它也可以被一个人用伸出的手指数来表示,这种方法写下来就是11111,这种计数法有个名字—— 一元计数法。罗马字中还有另一种表示5的符号——字符V。我们即将会看到5的第四种符号表示是二进制00000101。

只是简单的表示这些数值还不够,我们还必须能对这些数值进行运算。如果在计算机上能对以某种表示法编码的信息进行运算,我们就把这种特殊的表示法称为数据类型。每种指令集结构都有它自己的数据类型集,和对那些数据类型进行运算的指令集。在本书中,我们主要使用两种数据类型:用来表示我们要进行算术运算的正负整数的二进制补码整数,和用来表示我们想输入计算机或显示在计算机显示器上的键盘上的字符的ASCII码。在后面就会解释这两种数据类型。

事实上,在大多数计算机上还存在着多种数值表示方法。回忆在中学学习过的“科学计数法”,它要求你将十进制数621表示为6.21*102。在计算机中,也存在以这种形式表示的数字,并且也提供了对这种表示法的数值的运算。这种数据类型通常被称为浮点数。我们将在2.6节展示这种表示法。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值