Thread: Little vs Big Endian

  1. #1
    Registered User Wokzombie's Avatar
    Join Date
    Feb 2010
    Location
    Netherlands
    Posts
    14

    Little vs Big Endian

    I have been searching for info on Big Endian v. Little Endian, but the information I have found so far has has mostly been pretty vague.

    I know with big endian a single byte will have 8 bits from right to left (high to low) and little endian has 8 bits from left to right (low to high) in a single byte.

    But does this extend to multiple bytes as wel? As in, will 5 big endian bytes go from right to left and 5 little endian bytes go from left to right the same as the previous example?

    Or am I looking at this principle completely the wrong way?

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    It has to do with the arrangement of multi-byte quantities and has nothing at all to do with order of bits in a byte. Endianness has to do with how the components of quantities are addressed, and since bits are not addressable, endianness does not apply to them.

    In a little-endian representation, the least significant parts of a quantity occur at the lowest memory addresses, and vice versa for big-endian.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User Wokzombie's Avatar
    Join Date
    Feb 2010
    Location
    Netherlands
    Posts
    14
    It is quite late over here, but would you mind explaining yourself a bit further?

    Or if you know any good reading material, I would love it if you could point me in the right direction.
    Last edited by Wokzombie; 09-11-2010 at 04:44 AM.

  4. #4
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Croikey.

    Let's take a number, say 16,777,215. In hex you would write this on paper as 00FFFFFF (extending to 32 bits for simplicity's sake).

    Now for how this would appear in memory/registers in different endians...
    Little endian (e.g. Intel CPUs):-
    Code:
    Offset    00 01 02 03
    Data      FF FF FF 00
    Big endian (e.g. Motorola CPUs):-
    Code:
    Offset    00 01 02 03
    Data      00 FF FF FF
    In little endian, the least significant bits of a multi-byte integer are stored at the lowest address in memory.
    In big endian, the most significant bits of a multi-byte integer are stored at the lowest address in memory.

    Comprendez?

  5. #5
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    In addition, individual bytes are always in MSB order, regradless of applied endian.
    So for 0x12345678:-
    Code:
    Little endian:-
    Offset    00 01 02 03
    Data      78 56 34 12
    
    Big endian:-
    Offset    00 01 02 03
    Data      12 34 56 78

  6. #6
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    Endianness affects the byte ordering of words. The way that bits are arranged within a byte is the same on all architectures.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by SMurf View Post
    In little endian, the least significant bits of a multi-byte integer are stored at the lowest address in memory.
    In big endian, the most significant bits of a multi-byte integer are stored at the lowest address in memory.
    Perhaps that is better to say least and most significant byte, since that's all that's really changing.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Conceded. I'm still worried that I'll end up a teacher of this stuff.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Little endian Vs Big endian
    By karthik537 in forum C Programming
    Replies: 1
    Last Post: 08-02-2010, 07:55 PM
  2. Big Endian & Little Endian
    By swaugh in forum C Programming
    Replies: 18
    Last Post: 06-06-2007, 11:25 PM
  3. Big Endian Little Endian Complex- Converting Characters
    By bd02eagle in forum C Programming
    Replies: 3
    Last Post: 07-11-2006, 01:01 AM
  4. Big and little endian
    By Cactus_Hugger in forum C Programming
    Replies: 4
    Last Post: 10-12-2005, 07:07 PM
  5. Big endian/Little endian conversion
    By bonkey in forum Windows Programming
    Replies: 5
    Last Post: 09-25-2002, 02:29 PM