how to find your architecture is LittleEndian or BigEndian?



how to find your architecture is LittleEndian or BigEndian?..

Answer / kirankumaryakkala

ans. by using unions we can find it see.
union
{
char ch[2];
int i;
}u;
u.i=512;
printf("%d %d",u.ch[0],u.ch[1]);
printf("%d",u.i);

basically u will see this type of implementation while u r
going through some C books.

depending on the storage seen at ch[0],ch[1] u can find.

u can find the output as ch[0]=0,ch[1]=2 \\little endian
(or) ch[0]=2,ch[2]=0\\bigendian
like this u can find the endian....

Is This Answer Correct ?    3 Yes 1 No

Post New Answer

More C Interview Questions

what will be the output of this program........ main() { int a=2,b=4,c=6; printf("%d"); } why it gives the value of third variable.

6 Answers   HCL,


what is the advantage of using SEMAPHORES to ORDINARY VARIABLES???

2 Answers   NSN,


Do you know what are the properties of union in c?

0 Answers  


Which one would you prefer - a macro or a function?

0 Answers  


main() { unsigned int k = 987 , i = 0; char trans[10]; do { trans[i++] =(char) (k%16 > 9 ? k%16 - 10 + 'a' : '\0' ); } while(k /= 16); printf("%s\n", trans); }

4 Answers   Vector,


how does the C compiler interpret the following two statements p=p+x; q=q+y; a.p=p+x; q=q+y b.p=p+xq=q+y c.p=p+xq; q=q+y d.p=p+x/q=q+y

4 Answers   TCS,


What is the modulus operator?

0 Answers  


where does malloc() function get the memory?

1 Answers  


to convert a string without using decrement operater and string functions

1 Answers  


write a program to generate 1st n fibonacci prime number

12 Answers  


How can I handle floating-point exceptions gracefully?

0 Answers  


What is the size of enum in bytes?

0 Answers  


Categories