PDA

View Full Version : Big endian



kiros88
05-21-2010, 07:26 PM
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.

kermit
05-21-2010, 07:38 PM
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).

Sebastiani
05-21-2010, 07:48 PM
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:



int is_little_endian_machine( void )
{
static unsigned long value = 1;
static int result = *( unsigned char* )&value == 1;
return result;
}

kermit
05-21-2010, 07:52 PM
Simple. Just analyze the first byte of a multi-byte value, eg:



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?

Sebastiani
05-21-2010, 08:01 PM
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)...

tabstop
05-21-2010, 08:04 PM
Google says: Bash Tips (http://www.osmanoglu.org/index.php/computing/3-bashtips)

kermit
05-21-2010, 08:08 PM
Google says: Bash Tips (http://www.osmanoglu.org/index.php/computing/3-bashtips)

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.