Search Tutorials

Thursday, 18 April 2013

C code to check System is Big endian or Little endian

Little Endian: 
Little Endian means that the lower order byte of the number is stored in memory at the lowest address, and the higher order byte is stored at the highest address.

Big Endian:
Big Endian means that the higher order byte of the number is stored in memory at the lowest address, and the lower order byte is stored at the highest address.

C program:


#include <stdio.h>
int main()
{
unsigned int i = 1;
char *c = (char*)&i;
if (*c)
printf("Little endian");
else
printf("Big endian");
getchar();
return 0;
}

Output of the Above program may change according to your system:

check-System-is-Big-endian-or-Little-endian
check System is Big endian or Little endian


See also:
Convert little Endian to Big Endian in C

No comments:

Post a Comment

Back to Top