56

I was wondering, why some architectures use little-endian and others big-endian. I remember I read somewhere that it has to do with performance, however, I don't understand how can endianness influence it. Also I know that:

The little-endian system has the property that the same value can be read from memory at different lengths without using different addresses.

Which seems a nice feature, but, even so, many systems use big-endian, which probably means big-endian has some advantages too (if so, which?).

I'm sure there's more to it, most probably digging down to the hardware level. Would love to know the details.

2
  • 1
    It appears you're quoting the Wikipedia article on Endianness. The next paragraph states, "On the other hand, in some situations it may be useful to obtain an approximation of a multi-byte or multi-word value by reading only its most-significant portion instead of the complete representation; a big-endian processor may read such an approximation using the same base-address that would be used for the full value."
    – Wiseguy
    Commented Dec 18, 2012 at 7:25
  • 2
    True, that must be one advantage in using big-endian, but, are these the only reasons for which the two exist?
    – Rad'Val
    Commented Dec 18, 2012 at 18:23

2 Answers 2

57
+50

I've looked around the net a bit for more information on this question and there is a quite a range of answers and reasonings to explain why big or little endian ordering may be preferable. I'll do my best to explain here what I found:

Little-endian

The obvious advantage to little-endianness is what you mentioned already in your question... the fact that a given number can be read as a number of a varying number of bits from the same memory address. As the Wikipedia article on the topic states:

Although this little-endian property is rarely used directly by high-level programmers, it is often employed by code optimizers as well as by assembly language programmers.

Because of this, mathematical functions involving multiple precisions are easier to write because the byte significance will always correspond to the memory address, whereas with big-endian numbers this is not the case. This seems to be the argument for little-endianness that is quoted over and over again... because of its prevalence I would have to assume that the benefits of this ordering are relatively significant.

Another interesting explanation that I found concerns addition and subtraction. When adding or subtracting multi-byte numbers, the least significant byte must be fetched first to see if there is a carryover to more significant bytes. Because the least-significant byte is read first in little-endian numbers, the system can parallelize and begin calculation on this byte while fetching the following byte(s).

Big-endian

Going back to the Wikipedia article, the stated advantage of big-endian numbers is that the size of the number can be more easily estimated because the most significant digit comes first. Related to this fact is that it is simple to tell whether a number is positive or negative by simply examining the bit at offset 0 in the lowest order byte.

What is also stated when discussing the benefits of big-endianness is that the binary digits are ordered as most people order base-10 digits. This is advantageous performance-wise when converting from binary to decimal.


While all these arguments are interesting (at least I think so), their applicability to modern processors is another matter. In particular, the addition/subtraction argument was most valid on 8 bit systems...

For my money, little-endianness seems to make the most sense and is by far the most common when looking at all the devices which use it. I think that the reason why big-endianness is still used, is more for reasons of legacy than performance. Perhaps at one time the designers of a given architecture decided that big-endianness was preferable to little-endianness, and as the architecture evolved over the years the endianness stayed the same.

The parallel I draw here is with JPEG (which is big-endian). JPEG is big-endian format, despite the fact that virtually all the machines that consume it are little-endian. While one can ask what are the benefits to JPEG being big-endian, I would venture out and say that for all intents and purposes the performance arguments mentioned above don't make a shred of difference. The fact is that JPEG was designed that way, and so long as it remains in use, that way it shall stay.

3
  • 7
    I'll bet the second reason above is a common reason for big-endian. When programmers are reading octal/hex dumps of data, it's easier to translate big-endian printouts in your head. Hardware performance differences are probably negligible, so human factors is an appropriate deciding factor.
    – Barmar
    Commented Dec 24, 2012 at 21:59
  • 1
    Speaking of determining if a number is positive or negative, this usually not required to do integer math, most simple ALU designs handle both signed and unsigned integers using same circuit.
    – Ignas2526
    Commented Apr 17, 2013 at 11:11
  • 3
    Another advantage to logical endian (LE, where bit indices and byte indices both follow the same increasing flow) is that bit tests in bitmask arrays are simpler. For example on x86, the bts/btc (bit test and set/clear) instructions can update any arbitrary bit index in memory, and it doesn't matter how the bits are grouped (e.g. an std::vector of uint32_t vs uint8_t). On backwards endian (BE) machines, you can't simply read in a bitmask and twiddle the bits without also knowing the unit size, or else you access the wrong bit index. Commented Jan 20, 2021 at 3:55
1

I would assume that it once were the hardware designers of the first processors who decided which endianness would best integrate with their preferred/existing/planned micro-architecture for the chips they were developing from scratch.

Once established, and for compatibility reasons, the endianness was more or less carried on to later generations of hardware; which would support the 'legacy' argument for why still both kinds exist today.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.