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

Re: [SLUG] Re: Endian-ness.



On Tue, 4 Apr 2000, Michael Lake wrote:

> 
> David Fisher wrote:
> > Would some kind soul mind explaining what this Endian business is all about?
> > I have seen frequent references to it on this list but not elsewhere.
> 
> Lets say we write a program to store the three decimal numbers; 19, 19
> and 19
> In the computers memory they are stored as binary numbers. 
> 19 decimal is 10011 binary ie 1x16 + 0x8 + 0x4 + 1x2 + 1x1 = sums to 19
> 
> On a little endian machine those same three numbers stored sequentially
> in memory would be like so;
> 10011 10011 10011	ie the least significant bit is first.
> 
> On a big endian machine the same numbers would be like this in the
> memory;
> 11001 11001 11001	ie the most significant bit is first.

NO NO NO and again NO.

Endinanness refers to how pairs (or more) of bytes are stored. The
bytes are almost _always_ stored with the most significant bit first.
(Unless you've got some really weird architecture, and I don't know
how some of the older 12 bit DEC boxes stored stuff either).

So, consider the decimal numbers 21930 and 43605. In hex they can be
represented as 0x55AA and 0xAA55 respectively. In binary they can be
represented as

    01010101 10101010
    10101010 01010101

I added spaces for readability. Reading the first line from the right
to the left, there are zero lots of 2^15, one lost of 2^14, zero losts
of 2^13 ...... 1 lot of 2^1 and finally zero lots of 2^0. IE the most
significant bit is first.

The problem of endianness doesn't arise until we wish to store these
numbers somewhere - in memory or on disk or sent over the wire. 

On big endian machines, the most significant BYTE is stored first,
followed by the next most significant. So, these values would be
written to disk (for example) as (using hex notation):

    55AA
    AA55

On a little endian machine, each byte is stored most significant _bit_
first (just like in the big endian machines) BUT the _order_ of the
bytes is least significant BYTE first. So these same numbers would be
written to disk as

    AA55
    55AA
    

> > I was not hitherto aware that Jonathan Swift was a Linux user, nor can I find
> > any other reference to Unix in "Gulliver's Travels".
> 
> Yes the term was derived from the Little Endians who ate their eggs
> little ends first vs the Big Endians who ate their eggs big end first.

Literarily correct.

Regards
Peter
----------
Peter Samuel                                peter@nospam.eserv.com.au
Technical Consultant                        or at present:
eServ. Pty Ltd                              Peter.Samuel@nospam.ind.tansu.com.au
Phone: +61 2 9206 3410                      Fax: +61 2 9281 1301

"If you kill all your unhappy customers, you'll only have happy ones left"

--
SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
To unsubscribe send email to slug-request@nospam.slug.org.au with
unsubscribe in the text