Re: [Fwd: Endian'ess.]

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

 



Hi Amith,

I ran your code on my Big Endian Coldfire-5272 board and the output
I got was -

sizeof(Test) = 4
t1.w1 = 1234
t1.w2 = 5678
&t1.w1 = 314CD4
&t1.w2 = 314CD6

I think that should sort out all confusions..

--
Kishore

> -------- Original Message --------
> Subject: Endian'ess.
> Date: Thu, 08 Jul 2004 12:30:56 +0530
> From: amith <amith@multitech.co.in>
> To: KERNEL <kernelnewbies@nl.linux.org>
> 
> Hi all ,
>              a little off-topic.
> 
> #include
> #include
> 
> 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
> Typo > t1.w1 = 1234
> shud be > t1.w2 = 1234
> &t1.w1 =  6004
> Typo > &t1.w1 =  6006
> shud be >&t1.w2 = 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/
> 
>

--
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