Wednesday, November 4, 2015

Finding out the system is little endian or big endian system

Here first a value 1 is stored in a int variable. Address of that variable is taken and cast as a char address which will work only on the first byte of the word. If a value one is available in the char then its little endian system otherwise its big endian
# include <stdio.h>
# include <conio.h>
void main()
{
int i = 1;
char *c = (char *) &i;
if (*c)
printf("Little endian");
else
printf("Big endian");
getchar();
}
view raw endian.c hosted with ❤ by GitHub

No comments:

Post a Comment