Understanding Big and Little Endian Byte Order

Excellent explanation! Much Better Explained than other sources I’ve seen. Well done!

@salaz, Bob, Thura: Thanks!

Cảm ơn rất nhiều! / Thank You very much! / Merci beaucoup! / Danke Sehr! / …
But I still wonder that in Little-Endian, ‘UNIX’ will be stored as ‘XINU’, not ‘NUXI’ (??). Because the number UNIX is a double-word (4-byte): HIGH-word is ‘UN’ (2-byte), LOW-word is ‘IX’ (also 2-byte). And due to Little-Endian, I have the LOW-word stored first, then the HIGH-word second --> ‘IX’, ‘UN’.
Next, in each WORD-number, still due to Little-Endian, the number IX (2-byte) will be stored in usual order: X I. Same thing for the 2-byte UN number : N U.
So, a 4-byte ‘UNIX’ will be stored (in memory -of course) as: X I N U (!!!). Do I confuse something? Hope to hear from You soon… :slight_smile:

@chipvang: You’re welcome, gracias, danke! :slight_smile:

If UNIX was stored as a double-word (4 bytes) then it would become XINU. But, the problem refers to storing UNIX as two shorts: UN and IX. So if you switch the endian on each short, it becomes NU and XI, or NUXI.

Great question – it confused me too.

thanks a lot.

Great article … detailed view right from Basics !

Great article! However (there’s always a however for engineers…), I’d like to suggest a couple of additions:

  1. talk a bit about mixed-endian, like some ARM (and IBM?) processors have used. They can be BE for 16-bit values, but have two 16-bit values LE as a 32-bit read (or was that 32 and 64 - I still get confused).

  2. Also, your explanations and example are all software/firmware based/targeted. For us hardware designers, mostly using Verilog, LE naturally makes sense and is assumed by the language. For example, if I declare a 32-bit vector and assign a value to it, it’s naturally LE:

wire [31:0] my32bitregister;
assign my32bitregister = 32’h12_34_56_78;

In this case,
my32bitregister[ 7: 0] is 8’h78
my32bitregister[15: 8] is 8’h56
my32bitregister[23:16] is 8’h34
my32bitregister[31:24] is 8’h12

I think most of my big design headaches over the years have been byte/word swapping to convert endianness!

Hi
Your approach to the confusing topic is really simple.you made it easy to understand.
Thanks

pls tell me why the word address is jumping from 0 to 4…

Hey,
thank you very much for that introduction. It is way nicer to read than the respective Wikipedia entry.
One thing you may want to change are the pointer initialized to 0. It might be a little confusing because they’re actually NULL pointers. You mention that, but why not just let the addresses start at 1 instead of 0?

Keep up the good work :slight_smile:
JAAG

very nice article keep up the good work

I’m trying to interact from a little endian machine to a big endian - Motorola machine. I get data from the big endian machine in bytes. I never know the type of data packed in it. So I’m don’t know if I’m receiving integer or shot int or whatever type.

How can I rightly interpret the data in the little endian machine?

Great Article, I could understand the byte ordering better than any other source of Information. I still have one question which i am not able to understand. Say we have a binary data ( a JPEG Image) created in little endian machine and its transmitted to a big endian machine. If we compute a SHA1 hash of the file in both the machine do they give same result of they would give different hash.
If i read the file as byte by byte in base64 encoded format and hash them in both the machine. Please see i am not rendering the file, i am just interested in computing the hash of the file.

Mani

@Lakshminarayanan: Unfortunately, you need to know the data types in the byte stream if you want to convert from big to little endian.

@Mani: Thanks. SHA1 looks at data as a stream of bytes, so big and little endian shouldn’t matter. Also, file formats like JPEG usually have a standard format they agree on, so it will be the same file on both systems.

AUBE FUTI LY0L PLEX NEAI 000D. :slight_smile:

( BEAUTIFULLY EXPLAINED. )

KUDOS.

really a gud one…

great post, my lecturer couldn’t explain as good as you do

Boy… You cleared my issues which I was struggling with for two hours! trying to read a big endian based data from a file into C… Thanks…

@Harish, Neeraj, Johanes, Rahul: Thanks!

[…] This post was Twitted by zjtopspeed […]