Big endian vs. Little endian : Why I prefer big endian

Most of the processors are big endian : Sun sparc processorc, PowerPCs, Motorola 680×0, MIPS, and so on.

However, the one which has the most of the market share produces little endian processors, the Intel. Well, the AMD can be added to the list.

Isn’t it strange why others make big endian processors? I would like to start by defending Intel/AMD first. If a number is represented in binary, the left most part is the highest bit. It is very straight forward and reasonable. So, locating the higher part to higher address location is logical too. Probably the original x86 processor designers also thought that way.

However, in other aspect, it starts not being reasonable.

For example, let’s assume that you make a bit stream buffer and save it as a file. Let’s also assume that it is saved in the unit of 4 bytes.

Here are the data : 0x0A0B0102.

If it is saved to a file on a intel platform, it becomes 02 01 0B 0A.

If it is saved on a big endian system, it becomes 0A 0B 01 02

Now, if they are read into memory, they will be read as 0A0B0102 on the two platform. So far, there is no problem.

However let’s save 0x11223344 additionally.

On little endian systems, it is 02 01 0B 0A 44 33 22 11, while it becomes 0A 0B 01 02 11 22 33 44 on big endian systems. Because they are save in the unit of 4 bytes, they should be read into memory in the unit of 4 bytes to ensure the original semantics on little endian system.

When you make a kind of bit stream buffer, for example, you feed in additional data into the buffer. Let’s assume that you want to fill the buffer whenever there is enough empty slot in the bit stream buffer. So, someone already consumed 2 bytes from the buffer, so 2 more bytes are going to be fed into the buffer. After the first 4 bytes were read, the current file position is at the 5th bytes. You can say, “Oh.. now let’s read additional bytes.” Then from where will you read the “additional” bytes? On little endian system, it is the 8th bytes not the 5th bytes. So, you should read the next 4 bytes, and feed in the high 2 bytes into the bit stream buffer. So, to read the 4 bytes, and take out the high 2 bytes, an intermediate storage is necessary.

On the other hand, you can read actual next 2 bytes from the file on big endian systems. You don’t need any additional buffer, and you can read any data in whatever unit you want. So, to manipulate data, big endian system is more reasonable.

If we still write in assembly language, probably the x86 system would not be as popular as it does nowadays. :)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: