delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/10/12/11:30:48

Date: Fri, 12 Oct 2001 11:26:25 -0400
Message-Id: <200110121526.f9CFQPA15322@envy.delorie.com>
From: DJ Delorie <dj AT delorie DOT com>
To: djgpp AT delorie DOT com
In-reply-to: <8af9182.0110120054.62e8c03@posting.google.com>
(bywale-t AT zszosw DOT petex DOT com DOT pl)
Subject: Re: Newbie's question about big- and little-endians
References: <8af9182 DOT 0110120054 DOT 62e8c03 AT posting DOT google DOT com>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> 2. a<<4.
> 
>    And here is my first question: will the result be 0x23 0x40
> (0x2340) on first and 0x41 0x20 (0x2041) on second machine (just
> contents of memory were shifted)  or byte-order doesn't mean, and the
> result will be always 0x2340 (0x23 0x40 on first and 0x40 0x23 on
> second).

No, they'll be the same.  C operators are defined in terms of the
*value* not the representation.  0x1234 << 4 is 0x2340, no matter how
the chip decides to store it.

> 3. Some boolean-logic operation: for example a & 0xFF00 - will it be
> always 0x1200 or 0x1200 on first and 0x3400 on second machine?

It will always be 0x1200.

> 4. And now really fool question - 0x12 0x34 and 0x34 0x12 - which one
> is big-endian and which is little-endian.

Little endian stores the least significant byte first ("little end
first").  Big endian is most significant byte first.

0x1234 is stored like this:

Address:	0	1
Little-endian:	0x34	0x12
Big-Endian:	0x12	0x34

0x12345678 is stored like this:

Address:	0	1	2	3
Little-endian:	0x78	0x56	0x34	0x12
Big-Endian:	0x12	0x34	0x56	0x78

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019