Thread: Little endian Vs Big endian

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    53

    Little endian Vs Big endian

    Code:
    int main()
    {
    char a[]={1,2,3,4,5};
    char *cp;
    int *ip;
    clrscr();
    cp = a;
    ip=(int*)cp;
    printf("%d \n",*(cp+2));
    printf("%d \n",*(ip+1));
    }
    o/p:

    3
    1027

    The o/p value 1027 is because as pointer ip is a pointer to an int(if size of int is 2 bytes) then it will print the value 0x0304.

    what is the output of ( printf("%d \n",*(ip+1)) if it is little endian and what is the output if it is big endian machine?

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Whatever output you get on a big-endian machine, swap the bytes around for the output on a little-endian machine and vice-versa.
    Last edited by itCbitC; 08-02-2010 at 07:58 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Any significant Big Endian Machines?
    By abachler in forum Tech Board
    Replies: 9
    Last Post: 01-29-2009, 01:53 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