讀深入理解計算機系統 - 第一章 計算機系統漫遊 - 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的排列組合.

信息(正確的結果) = 位(正確的人) + 上下文(恰到好處的環境)

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