Thursday, July 12, 2012

Endianness


This post explains the concept of endianness of data .


The endianness of a data tells about the order in which the most significant byte or least significant byte in a large data item are stored in least memory address.

When the most significant byte in the large data item is stored at least memory address it is called Big-Endiann system.

When the least significant byte in the large data item is stored at least memory address it is called Little-Endiann system.

In brief the endiannes depends on which byte( Most significant or Least significant ) is stored at the first (least memory) address.


Here is the explanation with an example:

Lets take the IP address of the local host i.e 127.0.0.1 ( dotted decimal notation).

Now if the system we use is Big-Endian then the bytes are stored from least significant byte (LSB) at the first address(least memory address) followed by next byte etc.


LeastMemoryAddress+3 LeastMemoryAddress+2 LeastMemoryAddress+1 LeastMemoryAddress
127 0 0 1

Now if the system we use is Little-Endian then the bytes are stored from Most significant byte (MSB) at the first address(least memory address) followed by next byte etc.
LeastMemoryAddress+3 LeastMemoryAddress+2 LeastMemoryAddress+1 LeastMemoryAddress
1 0 0 127
Now you have learned about big-endiann and little-endiann sytems now yu may wonder where these systems are used in real worl applications . Are you ?? Ok.. I will give you a real world example... Most of the time network data uses Big-Endiann system and some systems like x86 programs use Little-Endiann system. Though it might depend on the designers choice of these systems(Big or Little ??) ... atleast this explanation serve as a good example ...

No comments:

Post a Comment