Endianness

Endianness:

Programmers who work on high level languages they don’t think about the hardware endianness or computer architectures; they only think about the code and the executable part and not how to convert little endian to big endian or vice versa.

But we should know how to deal with endianness; as sometimes it plays an important role and can create problem when transmitting from one computer and receiving on another whose endianness differ.

When communicating between computers, if the endianness differs of that two(computers), the data transmitted can’t be received in the actual form.

What is Endianness?

Endianness refers to the byte order in which data is stored in the memory; also describes the byte order sent over a digital link.

The term may also be used more generally for the internal ordering of any representation.

The endianness is categorized into two types:

  1. Little endianness
  2. Big endianness

Note: It is hardware dependent.

Little Endianness:

In this type of Endianness, the LSB byte is stored in the given lower memory address.


Big Endianness:

In this type of Endianness, the MSB byte is stored in the given lower memory address.


Big-endianness is the dominant ordering in networking protocols, such as in the internet protocol suite, where it is referred to as network order, transmitting the most significant byte first. Conversely, little-endianness is the dominant ordering for processor architectures and their associated memory.

 

 
Difference between Little and Big Endianness:


Practical:

Program to prove Endianness in your system:

#include<stdio.h>

void main()

{

int a=1;

char *c= (char *)&a;

if(*c)

printf(“Little Endianness\n”);

else

printf(“Big Endianness\n”);

}

Description:

we are storing 1 in variable “a”, i.e. 1 is stored in 32 bits; then we are storing the address of variable “a” in character pointer as it is a character pointer it will fetch only one byte(from left or from right depend on your system endianness) from four bytes(int data type).

Then we are checking value in character pointer, if there is 1 in char pointer then we can conclude the system is working on Little Endian; else Big Endian.

Note: you can also check by storing value 258 in “a” and check char pointer value equals to 2 or not; if (*c==2) then you can conclude that your system is working on Little Endian.

In case of, int a=258;



Follow for more,
Instagram: @coding_over_chai



Comments

Popular posts from this blog

Basic Structure of C Program