Endianness
seuchenrui@126.com
reference: Daniel Page. A practical introduction to computer architecture. Springer-Verlag London, 2009: 28 - 29
Usually, we use a little-endian convention by reading the bits from right to left, giving each bit is given an index. So writing the number 1111011(2) as the vector 1111011 we have that
- x0 = 1
- x1 = 1
- x2 = 0
- x3 = 1
- x4 = 1
- x5 = 1
- x6 = 1
If we interpret this vector as a binary number, it therefore represents 1111011(2) = 123(10). In this case, the right-most bit (bit zero or x0) is termed the least-significant while the left-most bit (bit n-1 or xn-1) is the most-significant. However, there is no reason why little-endian this is only option: a big-endian naming convention reverses the indices so we now read them left to right. The left-most (bit n-1 or xn-1) is the least siginificant. If the same vector is interpreted in big-endian notation, we find that
- x0 = 1
- x1 = 1
- x2 = 1
- x3 = 1
- x4 = 0
- x5 = 1
- x6 = 1
and if interpreted as a binary number, the value now represents 1101111(2) = 111(10).
The same issues of endianness need consideration in the context of bytes and words.
For example, one can regard a 32-bit word as consisting of four 8-bit bytes.
Taking W, X, Y and Z as bytes, we can see that the word can be constructed two ways.
- Using a little-endian approach, Z is byte zero, Y is byte one, X is byte two and W is byte three; we have the word constructed as W : X : Y : Z.
- Using a big-endian approach the order is swapped so that Z is byte three, Y is byte two, X is byte one and W is byte zero; we have the word constructed as Z : Y : X : W.
The following figure is demonstration of byte-ording.
Jari Nurmi. Processor design: system-on-chip computing for ASICs and FPGAs. Springer, 2007: 166
The following figure is another demonstration of byte-ording.
Patrick R. Schaumont. A Practical Introduction to Hardware/Software Codesign, second edition. Springer, 2013: 207