S
somenath
Hello All,
Is the following program can correctly determine the byte order of the
machine?
#include<stdio.h>
int main(void)
{
unsigned int x =1;
if ((x>>1) == 0)
printf("little-endian\n");
else
printf("Big-endian \n");
return 0;
}
In my opinion in case of little endian the 1 will be stored at the
last byte of the variable x. so if I shift it 1 byte the variable x
will have 0.But in case of big-endian 1 will be store at the right
most bye so right shifting by 1 should not be obtain 0. Is my
understanding correct?
I did not have access to big-endian machine. So i have not checked the
program in big-endian machine.
Thanks.
Somenath
Is the following program can correctly determine the byte order of the
machine?
#include<stdio.h>
int main(void)
{
unsigned int x =1;
if ((x>>1) == 0)
printf("little-endian\n");
else
printf("Big-endian \n");
return 0;
}
In my opinion in case of little endian the 1 will be stored at the
last byte of the variable x. so if I shift it 1 byte the variable x
will have 0.But in case of big-endian 1 will be store at the right
most bye so right shifting by 1 should not be obtain 0. Is my
understanding correct?
I did not have access to big-endian machine. So i have not checked the
program in big-endian machine.
Thanks.
Somenath