Left and right matter only if you are human.
Endianness的概念不是很复杂,这里以一段很简短的叙述描述清楚,以辅助读者在处理真值表的过程中首先确定其表示的方式。
Bit没有什么可说的,Byte通常由8 bit构成,Word由于计算机体系架构的不同通常也不一致,一个Word通常由个(2/4/6)Byte构成。
大端和小端的表示都是建立在Byte level的。
只有在Byte level你才可以描述大端或者小端,它跟Bit level没有任何的关系和联系。
通常情况下我们看到的MSB(Most Significant Byte)的B指的是Byte而非Bit。LSB(Least
Significant Byte)同理。
给如下示例:
By the courtesy of Prof. James L. Frankel
由上图可以看出,Big-endian的字节序是从左到右正常增长的,而Little-endian是自右向左的字节序。注意是字节序,不是比特序。
通常情况下人类可以接受和正常读取的是Big-endian,计算机表示的通常是Small-endian。
对于数字16,909,060来做一个示例(By the courtesy of Prof Alex
Quinn):
用16进制表示16,909,060带来的是所有的结果:
= 1 × 2²⁴ + 2 × 2¹⁶ + 3 × 2⁸ + 4 × 2⁰
= 0 x 0 1 0 2 0 3 0 4
这样的表征下,每两位是一个Byte,所以Big-Endian的表示应该为:
0 x 0 1 0 2 0 3 0 4
Small-Endian的表示应该为:
0 x 0 4 0 3 0 2 0 1
当然Endianness通常都是表现在Byte level的通常Word level都是Byte
level的偶数次倍数,其实如果有half-word level的表示,他也能展现出来endianness的特征。
结合我们的真值表的表示,通常情况下我们罗列的时候好比4 bit/4 输入/4 elementary variable,会有
0000 0/1
0001 0/1
0010 0/1
0011 0/1
0100 0/1
0101 0/1
0110 0/1
0111 0/1
1000 0/1
1001 0/1
1010 0/1
1011 0/1
1100 0/1
1101 0/1
1110 0/1
1111 0/1
假设函数为:
0000 1
0001 1
0010 0
0011 1
0100 1
0101 1
0110 1
0111 0
1000 1
1001 1
1010 0
1011 1
1100 1
1101 1
1110 1
1111 0
那么我们将以Big-endian的方式,自下而上表示为01111011
01111011
,虽然说Endianness跟bit
level没有任何关系,但是使用Big-endian的好处是,bit level和byte
level是等同顺序的,有助于我们的存储和处理,将来会在Kitty的设计理念中观察到。本文仅作必要的概述和参考,关于Endianness更加详细的内容,推荐读者参考CS:APP
2.1.3节“寻址和字节顺序”。