Little endian Vs Big endian

This is a discussion on Little endian Vs Big endian within the C Programming forums, part of the General Programming Boards category; 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)); } ...

  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,049
    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 08: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-07-2007, 12:25 AM
  3. Big Endian Little Endian Complex- Converting Characters
    By bd02eagle in forum C Programming
    Replies: 3
    Last Post: 07-11-2006, 02:01 AM
  4. Big and little endian
    By Cactus_Hugger in forum C Programming
    Replies: 4
    Last Post: 10-12-2005, 08:07 PM
  5. Big endian/Little endian conversion
    By bonkey in forum Windows Programming
    Replies: 5
    Last Post: 09-25-2002, 03:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21