Hardware Reference
In-Depth Information
Address
Big endian
Little endian
Address
0
0
1
5
9
2
6
10
3
7
11
3
2
6
10
1
5
9
0
4
8
0
4
8
4
4
7
11
8
8
12
12
13
14
15
15
14
13
12
12
Byte
Byte
32-bit word
32-bit word
(a)
(b)
Figure 2-11. (a) Big endian memory. (b) Little endian memory.
name) and two integers (age and department number). The string is terminated
with 1 or more 0 bytes to fill out a word. The big endian representation is shown
in Fig. 2-12(a); the little endian representation is shown in Fig. 2-12(b) for Jim
Smith, age 21, department 260 (1
×
256
+
4
=
260).
Transfer from
big endian to
little endian
Transfer and
swap
Big endian
Little endian
0
J
I
M
M
I
J
0
M
I
J
J
I
M
0
4
S
M
I
T
T
I
M
S
4
T
I
M
S
S
M
I
T
4
8
H
0
0
0
0
0
0
H
8
0
0
0
H
H
0
0
0
8
12
0
0
0
21
0
0
0
21
12
21
0
0
0
0
0
0
21
12
16
0
0
1
4
0
0
1
4
16
4
1
0
0
0
0
1
4
16
(a)
(b)
(c)
(d)
Figure 2-12. (a) A personnel record for a big endian machine. (b) The same
record for a little endian machine. (c) The result of transferring the record from a
big endian to a little endian. (d) The result of byte swapping (c).
Both of these representations are fine and internally consistent. The problems
begin when one of the machines tries to send the record to the other one over a net-
work. Let us assume that the big endian sends the record to the little endian one
byte at a time, starting with byte 0 and ending with byte 19. (We will be optimistic
and assume the bits of the bytes are not reversed by the transmission, as we have
enough problems as is.) Thus the big endian's byte 0 goes into the little endian's
memory at byte 0, and so on, as shown in Fig. 2-12(c).
When the little endian tries to print the name, it works fine, but the age comes
out as 21
2 24 and the department is just as garbled. This situation arises because
×
 
Search WWH ::




Custom Search