big-endian vs little-endian

The content of this article refers to this article about byte presentation. If you have not read it, do it now.

The big-endian style is about the order of bytes. The last byte becomes the first, the second becomes the second to last and so on. Let’s take the example from other article:

Let’s establish that it is a little-endian. Transforming it into a big-endian we have:

Of course, assuming that the previous one was big-endian. The order of bits inside the bytes does not change at all. It has nothing to do with it.

Assuming that the address 0x00000008 indicates data in the form of int (which is sometimes treated as a synonym of int32 – because it is 32-bit), then in the case of the first 6EC9514F the number comes out 1858687311, and in the case of 4F51C96E the number comes out 1330760046. Now let’s assume that there are characters. In the first case, according to the ASCII table, it is “nÉQO” and “OQÉn” in the second case.

Why are reversed values so different from each other? Why is there no such a pattern as with the characters like “nÉQO” and “OQÉn”?

The case looks much more complicated at first. In fact, when we display the result as words, all 4 letters are reversed as above. When we display half of the value, then they turn 2 characters side by side. However, when displaying string (text) as bytes, the letters will be in the same order. The third scenario is the same in little-endian and big-endian. The first two scenarios do not exist in the big-endian. Everything goes the same way.

I will give an example of a second scenario in little endian in C:

char* word = "ABCDEF";       // 1 char is 1 byte, so the whole has 6 bytes
int* p = (int *) word; // the int is 2 byte, that is 8-bit

6/2 = 3 adjacent shifts. The text is divided into 3 parts according to the “p” variable.

So the result is BA DC FE.

Endianess applies only to primitive types such as short, int, long, long etc. (such data types occur in programming languages), so displaying string (text) as bytes does not change the value. In the last example, the int on which the endianess works was implemented to work.

Published by juliagoda

https://github.com/juliagoda

Leave a comment

Design a site like this with WordPress.com
Get started