Thread: Big endian

  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,534
    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,708
    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:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    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,708
    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:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

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

  7. #7
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    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, 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