首先我们需要知道什么是小端字节序和大端字节序。
|
下面就让我们看看用程序怎么来查看主机的字节序:
#include < stdio. h>
#include < stdlib. h>
int
main( )
{
union {
short s;
char c[ sizeof ( short ) ] ;
}un;
un. s = 0x0102;
if ( sizeof ( short ) = = 2) {
if ( un. c[ 0] = = 1 && un. c[ 1] = = 2)
printf( "big-endian/n" ) ;
else if ( un. c[ 0] = = 2 &&un. c[ 1] = = 1)
printf( "little-endian/n" ) ;
else
printf( "unkown" ) ;
}
exit( 0) ;
}