读深入理解计算机系统 - 第一章 计算机系统漫游 - 1.1 信息 = 位 + 上下文

1.1 信息 = 位 + 上下文

先说一下位,计算机的最小单位,一个位可以取两个值1/0(高电平/低电平)代表两种状态(1个位=1bit).

但是世界事物千千万,无法用一个位来表示,怎么办呢? 某不知名人士说过,没有什么东西是0和1无法表示的,如果有…那就再加一个0和1.所以,在计算机中,一般由8位表示一组(即8bit=1byte, 1字节=1byte),而这一组可以表示2的8次方个字符(字母、符号或者数字),而这256个字符就构成了计算机系统的基础.

最早ascii是7位,后来欧洲那帮货给拓展到了8位,现在为了兼容其他国家给拓展的更多了,我这边理解一律按照8位.

下面来看一个简单的例子:

#include <stdio.h>
  
int main()
{
    printf("hello, world\n");
    return 0;
}

这是每个计算机系学生的编程第一课,每个程序员无论你现在使用的是什么语言,无论是C、C++、java、python、go、ruby或者其他,相信对helloWorld都不陌生,但是你知道从计算机的角度来看,这段代码是什么样子的吗?

让我们再深一步的观察一下这段代码的ASCII表示方法:

深入理解计算机系统1.1

SP: space空格
\n: 换行

那么看到这里是不是可以从这两个方向理解这段代码(实际上要比这复杂的多):
程序员视角: 代码(由字符串组成) --> byte(与ascii码一一对应) --> 一段连续的位符号

计算机视角: 一段连续的位符号 --> byte(与ascii码一一对应) --> 代码(由字符串组成)

其中如何将这一个个字符串分割、组合,依靠的就是上下文.

再来介绍上下文(Context),上下文对于我来说一直是一个充满玄学的词汇,也不知道谁提出的.在不通场景下,上下文代表不同的东西,如果要简单的理解的话,上下文就是环境、就是一段代码执行所需要的条件.下面这段是摘自Quora内的回答:

The facetious answer is "it depends on the context”(跟我说的差不多一个意思)

Context is the background information we need to understand the “unit of understanding” that we’re currently looking at. Ideally it would tell us in a straight-forward way what the assumptions and decisions that led to this point were.

More specifically, in Cucumber (and related tools), Context is used to get the system into a known state so that the Scenario you are about to execute makes sense as a standalone unit. If your scenario is about adding a text bundle to your mobile phone account, the context may be that you have a mobile phone and a calling plan, you’re registered on the system and logged in and the text bundle is available to you as a customer.

In a different context, in Domain Driven Design, a “Bounded Context” is an area of the system where a concept might use the same name as another area, but the meaning is different.
For example, a Customer means something different to the Billing system (who care about Billing Address, Credit Worthiness, Payment History etc) than to the Fulfilment System (who care about Delivery Address, Freight, Weight, Number of Parcels etc)

信息:个人理解就是计算机内的有效数据,可以被程序员理解的直观的数据和被机器读懂的指令. 这些数据的构成就是无数个0和1的排列组合.

信息(正确的结果) = 位(正确的人) + 上下文(恰到好处的环境)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章