1

A program compiled for a SPARC ISA writes a 32-bit unsigned integer 0xABCDEF01 to a file, and reads it back correctly. The same program compiled for a Pentium ISA also works correctly. However, when the file is transferred, the program incorrectly reads the integer from the file as 0x01EFCDAB. What is going wrong?

Badger
  • 301
  • 3
  • 15

1 Answers1

2

SPARC and Pentium use a different byte ordering ("endianness") in memory and on storage:

  • SPARC uses big-endian: the most-significant byte of the integer comes first
  • Pentium uses little-endian: the least-significant byte of the integer comes first

I.e. when the file is transferred to machine with a different endianness, the bytes of an integer seem to be in a reversed order.

JimiLoe
  • 950
  • 2
  • 14
  • 22