Endian'ess.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all ,
a little off-topic.


#include<stdio.h>
#include<string.h>

typedef struct test
{
   unsigned short w1;
   unsigned short w2;
}Test;

Test t1;

unsigned long temp = 0x12345678;

main()
{
   printf(" sizeof(Test) = %d\n",sizeof(Test));
   memcpy(&t1,&temp,4);
   printf(" t1.w1 = %X \n",t1.w1);
   printf(" t1.w2 = %X \n",t1.w2);
   printf(" &t1.w1 = %X \n",&t1.w1);
   printf(" t1.w2 = %X \n",&t1.w2);
}

output:
t1.w1 = 5678
t1.w1 = 1234
&t1.w1 = 6004
&t1.w1 = 6006



i tried the above code on x86 and ARM , both gave me the same results. Both x86 and ARM are little-endian , or arent they? . Could someone explain this result with respect to the definition of Little Endian . which goes (one of them) as :
Little Endian: the least significant byte of a multi-byte data field is stored in the lowest memmory address.


Now, i have a couple of doubts :
1) i read somewhere on the net, that a processor can be set to either Little endian or Big endian, configurable ?
2) Could someone explain this with respect to the Little Endian definition given above.



6004 6006 _________________ | 5678 | 1234 | |________|________ | t1.w1 t1.w2

Any good links to the Endianess would be great.

thanks.

cheers,
Amith




-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux