• admin@embedclogic.com

Little Endian And Big Endian Theory

Endianness is the attribute of a system which decides the representation of a word in memory. Some system saves the most significant byte of a word at starting address while some stores the least significant byte at base address.it depends on your system endianness. On the basis of word representation in a system, Endianess divided into two category –

  • Little Endianess (Right to left)
  • Big Endianess (Left to Right)

Little Endian System-

In the Little-endian system, a least significant bit(LSB) containing byte stores on the base address(0x00000000) of a word and rest of the byte stores from right to left at incrementing addresses.

Address Little Endian System
0x00000000 0x0000000D
0x00000001 0x0000000C
0x00000002 0x0000000B
0x00000003 0x0000000A

Big Endian System-

The big Endian system is opposite to the little endian system.Big Endian System stores Most significant bit(MSB)containing byte at the very first location(0x00000000)and rest of the byte stores from left to right at incrementing address.

Address Big Endian System
0x00000000 0x0000000A
0x00000001 0x0000000B
0x00000002 0x0000000C
0x00000003 0x0000000D

Example:

Little endian System: Intel x86-64 series processor, Zilog Z80, Altera Nios II.

Big Endian System:  Motorola 68000 processor, IBM system etc.

Know your system Endianness-

Program to find your system Endianness-

if your system is Intel x86 or X64 then the output is:

if your system is Motorola  output is:

Why is Endianess so important?

Suppose we have a system in which a Motorola processor device is working as a transmitter and Intel x86 as a receiver.

Big Endian Device (Motorola ) sent a word data 0x0A0B0C0D to your Little Endian Device. How your big-endian data treated by Little Endian device.

AddressBig Endian SystemLittle Endian System
0x000000000x0000000A0x0000000D
0x000000010x0000000B0x0000000C
0x000000020x0000000C0x0000000B
0x000000030x0000000D0x0000000A

so we can see that if we save big-endian data in the little endian system without conversion then transmit data will never match with received data.

So we have to convert big endian data in the little endian format before saving into little endian intel device otherwise you will receive reverse values that won’t make sense.

Big Endian To Little Endian Conversion:

we can use following C code to convert big endian data into little endian –

output :

Little Endian To Big Endian Conversion:

if you are getting data from the little Endian system then use below C code for conversion before saving into Big Endian system memory.

output :

Which One is better little or Big Endian?

Choice of system endianness depends on your system architecture.there is no advantage of one over other.Big Endian Format is commonly used in networking for data transmission while little endian is the favorite of microprocessor.so we can say that both endianness has their own significance.

Although I have tried to cover most of the part related to this topic your suggestion and comment are always welcome to improve this article. I also request you to send me if you find any error in this article .thank you so much for reading 🙂