tags:

views:

262

answers:

4

Why did some processor manifacturers decide to use

  • Little endian
  • Big endian
  • Middle endian
  • Any others?

?

I've heard that with big endian one can find out faster, if a number is negative or positive, because that bit is the first one. (This doesn't matter on modern CPUs, as individual bit can't be accessed anymore.)

+1  A: 

Using the endianness of the CPU (no matter little or big) gives you the speed benefit on arithmetics: you can add, subtract etc. multibyte integers directly in memory.

Using a predefined, prescribed endianness (no matter little or big) in a file format gives you the benefit of being able to read the file on any system, no matter the endianness of the CPU of the other system. Systems with the right endianness can read the file faster (if the read routine is written and optimized properly), but even systems with the wrong endianness can read it. Usually, the speed difference is negligable (except for very large files with lots of integers), so it is a good idea to first measure the maximum possible speed gain of optimizing the read routine.

Some file formats (for example TIFF) support both endianness. In this case it is a good idea to generate the file with the CPU's endianness, assuming the file would be post-processed on the same machine, or a similar machine.

pts
Actually, for a large file, even if only integers, you're going to be limited by the speed at which you can read it from disk or network if the only processing you need to do is swap ends. In fact, on modern CPUs you can do a lot more work than that before you're slower than your I/O, which is why often storing files on disk compressed, and decompressing them on the fly as you process them is faster than just processing an uncompressed file.
Curt Sampson
Can you please explain how Endianness is important for reading Files. How does it matter if I read a Text File ?
Geek
Well if for example you are reading a file which is a text file storing UTF16LE (little endian) characters, then if your native format was UTF16BE (big), you would have to reverse the sense of the characters as they were read in. However, as Curt Samson points out, this probably makes little difference since the speed of the CPU and main memory is much higher than the disk
1800 INFORMATION
+2  A: 

There is no particular benefit of big or little endian as such, except using native CPU endianness or handling specified file endianness.

The reason why both big and little endian coexist is that different CPU makers used different conventions for representing multibyte data, and no standard emerged at the time.

mouviciel
+8  A: 

The benefit of little endianness is that a variable can be read as any length using the same address.

For example a 32 bit variable can be read as an 8 bit or 16 bit variable without changing the address. This may have limited benefit these days, but in the days of assembler and limited memory it could be a significant advantage

David Sykes
What about big endian?
Georg
I'm not sure there is an actual benefit to big endian, other than compatibility with other systems. In most high level languages the endianness is irrelevant anyway
David Sykes
One benefit of big-endian is that you can read 16-bit and 32-bit values as most humans do; from left to right. A memory dump of 4 bytes that says `ffaa8800` is actually `0xffaa8800` not `0x0088aaff` as little-endian would be.
PeyloW
+1  A: 

Different Endian's give different benefits in computations. It is generally a tradeoff that the designers of the machine choose from.

Geek
Which benefits? That's what I am looking for.
Georg