0
votes

I was reading an article which was explaining the difference in between little and big endian. I understand that big endian stores the data "big end" first and that little endian stores the data "little end" first. My confusion is in the following block of text:

Big endian machine: I think a short is two bytes, so I'll read them off: location s is address 0 (W, or 0x12) and location s + 1 is address 1 (X, or 0x34). Since the first byte is biggest (I'm big-endian!), the number must be 256 * byte 0 + byte 1, or 256*W + X, or 0x1234. I multiplied the first byte by 256 (2^8) because I needed to shift it over 8 bits.

I don't understand why they did a bit shift of 8 bits. Also, here's another block of text I don't understand:

On a big endian machine we see:

Byte: U N I X Location: 0 1 2 3

Which make sense. U is the biggest byte in "UN" and is stored first. The > same goes for IX: I is the biggest, and stored first.

On a little-endian machine we would see:

Byte: N U X I Location: 0 1 2 3

If my understanding is correct, wouldn't it be "INUX, " on a little-endian machine? The full article is at https://betterexplained.com/articles/understanding-big-and-little-endian-byte-order/.

If anyone could clear this up, that would be wonderful.

1

1 Answers

0
votes

Alright, so I understand how big and little endian work now:

I'll address the issue I had understanding the second block of text. Basically, in the article, the author stated that if we stored the word, "UNIX, " as a couple of shorts (not longs), then the final result would be "NUXI." I'll now address the issue I had understanding the first block of text. Basically, the bit shift is done so as to switch the arrangement of the bytes in memory so that, in the case of big endian, the most significant byte is first, and, in little endian, the least significant byte is first.