ì Computer Systems and Networks ECPE 170 – Jeff Shafer – University of the Pacific Endianness
2 Lab Schedule Activities Assignments Due This Week Lab 8 ì ì Due by Mar 27 th 5:00am Network programming ì ì Endianness ì Lab 9 ì Lab 8 – Network ì Due by Apr 3 rd 5:00am ì Programming Computer Systems and Networks Spring 2017
3 Endianness In typical computer memory, ì each address (location) stores one byte If we have a one-byte integer, how is that stored in ì memory? If we have a two-byte integer, how is that stored in ì memory? If we have a four-byte integer, how is that stored in ì memory? Endianness = Byte Ordering Computer Systems and Networks Spring 2017
4 Endianness Example Address “Option A” “Option B” 32-bit hexadecimal number ì 0x12345678 0 0x12 0x78 Composed of 4 bytes: ì 0x12 0x34 0x56 0x78 1 (MSB) (LSB) 0x34 0x56 Two possible arrangements: ì 2 0x56 0x34 3 0x78 0x12 Computer Systems and Networks Spring 2017
5 Endianness Example Address Big Little 32-bit hexadecimal number ì Endian Endian 0x12345678 0x12 0x78 0 (MSB) (LSB) Composed of 4 bytes: ì 0x12 0x34 0x56 0x78 1 (MSB) (LSB) 0x34 0x56 Two possible arrangements: ì 2 0x56 0x34 Big Endian ì Little Endian ì 3 0x78 0x12 Computer Systems and Networks Spring 2017
6 Endianness How is DEADBEEF 16 stored in little and big endian ì formats at address 21C 16 ? Little endian ì ì 21C 16 =EF 16 ì 21D 16 =BE 16 ì 21E 16 =AD 16 ì 21F 16 =DE 16 Big endian ì ì 21C 16 =DE 16 ì 21D 16 =AD 16 ì 21E 16 =BE 16 ì 21F 16 =EF 16 Computer Systems and Networks Spring 2017
7 Big Endian –vs– Little Endian Big-Endian CPU Little-Endian CPU Most significant byte (MSB) Least significant byte (LSB) ì ì comes first (stored in lower comes first (stored in lower memory address) memory addresses) Examples Examples ì ì Motorola 68000 Intel x86/x86-64 ì ì Java virtual machine DEC Alpha ì ì IBM PowerPC (by default, ARM (by default, also can ì ì can also be little endian) be big endian) Computer Systems and Networks Spring 2017
8 Etymology of “Endiann” Origin in 1980s ì Reference to Swift's ì Gulliver's Travels , in which the Lilliputians were divided into two camps: Those who ate their eggs ì by opening the ‘big’ end Those who ate them by ì opening the ‘little’ end In other words, ì a trivial distinction Computer Systems and Networks Spring 2017
9 Do I Care? ì When do I need to care that some computers are big-endian and others are little endian? What happens if I open big-endian data on a little- ì endian computer? ì Endianness must be considered whenever you are sharing data between different computer systems Reading/writing data files to disk ì Reading/writing data files to network ì Computer Systems and Networks Spring 2017
10 Best Practices Pick one format and stick with it! ì Example: Data sent over the network will always be in ì big-endian format regardless of who sends it ì Networks are big-endian “by tradition” Example: Data written to disk will always be in little- ì endian format regardless of who writes it Convert between data storage/transfer format and ì internal representation as needed Example: Little-endian machines convert to big-endian ì before sending data onto the network (and convert back upon receiving data from the network) Computer Systems and Networks Spring 2017
11 Examples in Industry http://download.intel.com/design/intarch/papers/endian.pdf Computer Systems and Networks Spring 2017
Recommend
More recommend