Convert Big Endian to Little Endian?

Both of technique is used to store bits in memory address.

Big Endian:-  the most significant byte is stored in  the smallest address

Little Endian:- the least significant bytes are stored in the largest address

Example to store 1234 number

Big Endian                                                                         Little Endian

Address          Number                                            Address        Number

1000                   1                                                   1000                4

2000                    2                                                   2000                3

3000                    3                                                   3000                2

4000                    4                                                  4000                  1

PROGRAM

#include <stdio.h>

/* function to show bytes in memory, from location start to start+n*/
void show_mem_rep(char *start, int n)
{
int i;
for (i = 0; i < n; i++)
printf(” %.2x”, start[i]);
printf(“\n”);
}

/*Main function to call above function for 0x01234567*/
int main()
{
int i = 0x01234567;
show_mem_rep((char *)&i, sizeof(i));
getchar();
return 0;
}

.above program for little endian : 67 45 23 01

big endian : 01 23 45 67

rakesh

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to toolbar