Skip to main content
Logo image

Dive Into Systems: Exercises

Section 4.7 Integer Byte Order

Checkpoint 4.7.1. Byte Ordering.

(a) Little Endian Machines.

    On a little endian machine, which byte of x is stored at the lowest address in memory?
  • 0xCD
  • Correct!
  • 0xAB
  • Incorrect.
  • 0xBC
  • Incorrect.
  • 0xAD
  • Incorrect.

(b) Big Endian Machines.

    On a big endian machine, which byte of x is stored at the lowest address in memory?
  • 0xAB
  • Correct!
  • 0xCD
  • Incorrect.
  • 0xBC
  • Incorrect.
  • 0xAD
  • Incorrect.

Checkpoint 4.7.2. Integer Byte Order.

An int variable number is stored in four bytes in memory. Suppose its address is 0xFF000BD4. Given the contents of memory shown below:
Memory Address in Hex Data in Hex
0x FF00 0BD4 0x88
0x FF00 0BD5 0x77
0x FF00 0BD6 0x66
0x FF00 0BD7 0x55
What’s the value of number if the system stores integers in little-endian format? (express the value in hexadecimal)
What’s the value of number if the system stores integers in big-endian format? (express the value in hexadecimal)
Hint.
See ch4.7. The little-endian format stores data starting from the least-significant byte ("little end") to the most-significant byte in consecutive addresses.

Checkpoint 4.7.3. Byte Ordering.

    Assume that you are using an x86-based (little-endian) computer and receive a 4-byte int value sent from another computer over the Internet without either sender or receiver converting the integer to/from network byte order. In which of the following scenarios would you misinterpret the value of that number if you were to store it directly into a 4-byte int variable?
  • The sender was also a little-endian computer.
  • Incorrect
  • The sender was a big-endian computer.
  • Correct!
  • Both A and B.
  • Incorrect.
  • Neither A nor B
  • Incorrect.
Hint.
Consider the endianness of x86 and a network.