Big endian

This is a discussion on Big endian within the Linux Programming forums, part of the Platform Specific Boards category; Is there a way to tell if your system is big endian or little endian with out running a program ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    192

    Big endian

    Is there a way to tell if your system is big endian or little endian with out running a program cuz I dont have gcc install? either sudo so i cant sudo install it.

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Well I can tell you that if you are using an Intel x86 based system, it is little endian. If you have a PowerPC, (old Apple machines) it is big endian (Apparently that architecture can do both).

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    Quote Originally Posted by kiros88 View Post
    Is there a way to tell if your system is big endian or little endian with out running a program cuz I dont have gcc install? either sudo so i cant sudo install it.
    Simple. Just analyze the first byte of a multi-byte value, eg:

    Code:
    int is_little_endian_machine( void )
    {
        static unsigned long value = 1;
        static int result = *( unsigned char* )&value == 1;
        return result;
    }
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  4. #4
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Quote Originally Posted by Sebastiani View Post
    Simple. Just analyze the first byte of a multi-byte value, eg:

    Code:
    int is_little_endian_machine( void )
    {
        static unsigned long value = 1;
        static int result = *( unsigned char* )&value == 1;
        return result;
    }
    Yes, but is the OP not stating that he/she has no access to a compiler?

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    Quote Originally Posted by kermit View Post
    Yes, but is the OP not stating that he/she has no access to a compiler?
    Doh! Yeah, I misread that (read: wasn't paying attention)...
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Google says: Bash Tips

  7. #7
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Quote Originally Posted by tabstop View Post
    Google says: Bash Tips
    Very good - thanks for finding that tabstop. I did not think of using the shell to check, but I will certainly remember this for future use.

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, 12: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

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