Code: The Hidden Language of Computer Hardware and Software 总结

本文从两个小朋友用手电筒交流的故事引入,探讨了什么是Code及其存在的意义,例如Morse code和Braille code。接着,介绍了电流产生和灯泡点亮的原理,以及如何利用电路实现远距离通信,如电报系统。文章还讨论了数字系统,特别是二进制系统在计算机中的应用,以及如何使用不同逻辑门构造二进制加法器。最后,作者阐述了如何通过补码系统在计算机中进行减法运算。
摘要由CSDN通过智能技术生成

Best Friends

在这个章节中,作者首先给出了这样一个现实场景:就是2个关系很好的小朋友,他们隔窗相望,想在晚上交流,但是由于父母的限制,他们没有电话,不能开灯,只有一个手电筒。在这种情况下,他们如何去交流想法呢?作者依次给出如下方法:

  1. 用手电筒在空中写字母
  2. 字母表中的每个字母都对应手电筒的闪烁,比如,A-1个闪烁; B-2个闪烁……
  3. 代替闪烁,而是用 Morse code 去表示相应的字母

这本书的名字就叫做 Code,那么什么是 Code 呢? 作者给出了如下的定义:

In this book, the word code usually means a system for transferring information among people and machines. In other words, a code lets you communicate.

根据这个定义,我们可以找出很多这样的系统。比如:英语单词表(当你和别人说 cat 的时候,对方就知道你指的是一只猫,而不是别的什么东西),Java 编程语言(当你写一句代码的时候,机器知道如何去执行它),手语(聋哑人可以用其交流)。我们其实还可以找到很多这样的系统。

其实我感觉作者眼中的 Code 是一种映射系统,那么为什么要有这层系统存在呢?大家可能会感觉多了这一层系统多麻烦啊!我想说的是,它们既然存在,就一定是在某种情况下,它们会更有优势。

比如,Morse code 为什么会被发明出来?大家可以想像一下,如果大家都是面对面的这种交流,英语单词表这种 Code 就完全足够了,如果有人用 Morse code 去交流,你可能会感觉这些人有脑子有问题。但是如果像上面那种远距离传递信息的情况呢?你传递 dot 和 dash 容易,还是 传递 letter 比较容易呢?

在有些情况下,你必须要创造出另一种 Code 才能去解决问题。比如一个正常人和一个失去了听觉,视觉,和说话能力的人来交流,显然英语单词表这种 Code 就不行,因此你需要创造出另一种让这2类人都可以理解的 Code,只有这样,他们才可以用这种 Code 去传递信息。

Codes and Combinations

Morse code 是一种 binary code,因为它只有2个组成要素 - a dot and a dash. 上一章节中是字母到 Morse code 的映射,这对发送 Morse code 的人很方便,但是对接收 Morse code 的人很不方便,这章中作者做了一个从 Morse code 到字母的映射,从只有1个元素开始,然后2个,3个,……

Braille and Binary Codes

如何让一个让盲人可以阅读呢? Valentin Haüy 发明了一套可以通过触摸来阅读的系统,这个系统纸上的字母都是凸起的。但是这个系统非常难用,只有几本书用这个系统。

Valentin Haüy 陷入了一个范式,他认为 A 在纸上就应该像 A 的样子,B 就是 B 的样子,这就像第1章节中用手电筒直接在空气中写字母一样。大家想一想,如果要是你应该去怎么解决这样一个问题。在回答这个问题之前,我们的系统应该是什么样的?首先,这个系统的目的就是要向盲人去传递信息,并且要容易在纸上表达出来。没错,聪明的 Louis Braille 发明出了一种 Code 做到了这点。下图中就是 Braille code:

Braille code

具体细节请参考书籍,这里我就不过多要介绍了。

Anatomy of a Flashlight

在这章中,作者主要阐述电流是如何产生的,从而使灯泡亮起来。

The chemical reaction can’t proceed unless there’s some way that the extra electrons can be taken away from the negative terminal of the battery and delivered back to the positive terminal. So if the battery isn’t connected to anything, nothing much happens. (Actually the chemical reactions still take place, but very slowly.) The reactions take place only if an electrical circuit is present to take electrons away from the negative side and supply electrons to the positive side. The electrons travel around this circuit in a counterclockwise direction:

Anatomy of a Flashlight

大家通常都会认为是电池提供电量到电路中。但是,从上面的介绍中,我们也可以认为是:电路提供一种方式,让电池发生化学反应。电路从电池的负极拿走电子,然后把它们运送到电池的正极。直到电池内的所有化学物质耗尽,电池内的反应会一直发生。

我们可以有这样一个类比:电流类似于管子中的水流,电压类似于水压,阻力类似于水管的宽度–管子越细,阻力越大。

Seeing Around Corners

你有个好朋友住在隔壁,在这种情况下,你就不能用手电筒去发送 Morse code 了,现在让我们自己用电池,灯泡,开关,和导线制作一个我们自己的手电筒吧!

Seeing Around Corners

上图中的 V 代表电压,它也可以表示真空。我们可以把 V 看作是电子真空,把土地看作是电子的海洋,电子真空从土地上拉来电子,通过电路,电子经过灯泡,从而点亮它。上图中那个比较奇怪的符号(4个短线)代表 ground,a ground is a physical connection with the earth.

通过导线,我们可以摆脱距离的限制。通过提高电压,增加导线长度,减小电阻,从而可以使我们与远距离的朋友们互相交流。但是,导线的不可能无限长,按照上面的模式,最多也就能几百米远。那么我们如何来实现更远距离的信息传递呢?

Telegraphs and Relays

电报背后的思想其实很简单:You do something at one end of a wire that causes something to happen at the other end of the wire. 下图就是一个电报系统, When the telegraph key was pressed, the electromagnet in the sounder pulled the movable bar down and it made a “click” noise. When the key was released, the bar sprang back to its normal position, making a “clack” noise. A fast “click-clack” was a dot; a slower “click…clack” was a dash.

Telegraphs and Relays

电报的发明标志着现代通讯的开始,第一次,人们交流可以超过眼睛能看到的和耳朵能听到的距离,而且比马飞奔的速度还要快。尽管一些电报系统能进行大约300多米的通信,但是,我们依然做不到更远距离的通信,于是人们就想出了一个解决方案,发明了继电器,系统就被改进成下图的样子:

Telegraphs and Relays

继电器是一个伟大的设备,它无疑也是个开关,但是它的开与关不用人手去控制,而是用电流。

Our Ten Digits

这章主要介绍了我们今天使用的 number system - Hindu-Arabic or Indo-Arabic 相比与其它 number system 的好处,以及它的一些特点:

  • The Hindu-Arabic number system is said to be positional
  • There’s no special symbol for ten
  • Zero

The lowly zero is without a doubt one of the most important inventions in the history of numbers and mathematics. What’s best about the positional system of notation isn’t how well it works, but how well it works for counting systems not based on ten.

Alternatives to Ten

之所以我们人类的 number system 是 base ten 的,是因为我们本身就有10个手指,如果我们人类的手指像下图一样,那我们生活中的数字系统就很有可能是8进制的,那么我们的数字世界就只有0,1,2,3,4,5,6,7.

Alternatives to Ten

上图的最右面的手指可以看到有个10,这里的10并不代表具体的数量,为了不混淆,你可以把它读成 one zero,它只是代表上图中手指的个数。如果我们在用这个8进制的系统,当数量达到10(one zero)时,我们就可以进位,这就是基于 positional 的 数字系统的伟大之处,你甚至可以用5进制,3进制,随你怎么做。

既然这样,看来2进制系统是最适合计算机的,In previous chapters, we’ve been looking at switches and wires and lightbulbs and relays, and any of these objects can represent the binary digits 0 and 1: A wire can be a binary digit. If current is flowing through the wire, the binary digit is 1. If not, the binary digit is 0. A switch can be a binary digit. If the switch is on, or closed, the binary digit is 1. If the switch is off, or open, the binary digit is 0. A lightbulb can be a binary digit. If the lightbulb is lit, the binary digit is 1. If the lightbulb is not lit, the binary digit is 0. A telegraph relay can be a binary digit. If the relay is closed, the binary digit is 1. If the relay is at rest, the binary digit is 0. Binary numbers have a whole lot to do with computers.

Bit by Bit by Bit

Letters and words and Morse code and Braille and decimal digits convey information as well. But in the computer age, the bit has come to be regarded as the basic building block of information.

Information 代表的是在2种或更多种可能之间的一种选择,比如,当我们用另一个人交流的时候,every word we speak is a choice among all the words in the dictionary. 如果给字典中的每个 word 用数字编号,我们也可以用数字来准确地传达我们想要传递的信息,当然了,沟通的2人之间要明白具体的数字表达什么含义。The flip side of this is that any information that can be reduced to a choice among two or more possibilities can be expressed using bits. 比如我们有2个bit,因此我们有4种可能,00,10,01,11,但是当我们想表达信息的时候,我们只会拿出这其中的一种可能去传递出去。同时,The more bits we have, the greater the number of different possibilities we can convey.

As we shall see later in this book, bits can represent words, pictures, sounds, music, and movies as well as product codes, film speeds, movie ratings, an invasion of the British army, and the intentions of one’s beloved. But most fundamentally, bits are numbers. All that needs to be done when bits represent other information is to count the number of possibilities. This determines the number of bits that are needed so that each possibility can be assigned a number.

Logic and Switches

与传统代数不一样的是,Boolean algebra 的操作数是类别,传统代数的那些法则它也一样可以用,比如:commutative, associative, and distributive rules,但是在 Boolean algebra 中, + 操作符 is distributive over the x 操作符:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值