/* * HP-UX 9.x * cc -Aa -D_HPUX_SOURCE * HP-UX * cc -Ae * cc -Ae +DA2.0W (64) * IRIX * cc -o32 * cc -n32 -mips3 * cc -64 -mips3 (64) * Solaris * cc -xarch=v9a (64) * Tru64 * cc (64) */ #include #include #include char *out_c(unsigned int c); static char s[18]; int main( int argc, char **argv ) { #ifdef __STDC__ signed char sc; #endif /* HP-UX defines __LP64__ */ #if defined(_LP64) || defined (__arch64__) || defined (__mips64) || defined (__LP64__) # define ARCH64 1 #endif #ifdef __sgi #if (_MIPS_SZPTR == 64) # define ARCH64 1 #endif #endif #if defined __alpha # define ARCH64 1 #endif #ifdef ARCH64 #define D_WORD int #else #define D_WORD long #endif static unsigned D_WORD dw; /* Linux, Mac OS X, maybe gcc generic? */ #ifdef BYTE_ORDER printf("BYTE_ORDER defined (%d)\n",BYTE_ORDER); # if ( BYTE_ORDER == BIG_ENDIAN ) printf("BYTE_ORDER is BIG_ENDIAN\n"); # define HOST_IS_LITTLE_ENDIAN 0 # elif ( BYTE_ORDER == LITTLE_ENDIAN ) printf("BYTE_ORDER is LITTLE_ENDIAN\n"); # define HOST_IS_LITTLE_ENDIAN 1 # elif ( BYTE_ORDER == PDP_ENDIAN ) printf("BYTE_ORDER is PDP_ENDIAN\n"); # define HOST_IS_LITTLE_ENDIAN 0 # endif #else /* Intel, Alpha */ # if defined(__i386__) || defined (M_I86) || defined (_M_IX86) ||\ defined (WIN32) ||\ defined(__osf__) # define HOST_IS_LITTLE_ENDIAN 1 # else /* MIPS SGI IRIX */ # ifdef _MIPSEB printf("_MIPSEB defined (IRIX MIPS big endian)\n"); # define HOST_IS_LITTLE_ENDIAN 0 # endif # ifdef _MIPSEL printf("_MIPSEL defined (IRIX MIPS little endian)\n"); # define HOST_IS_LITTLE_ENDIAN 1 # endif /* I don't remember which one defines this: */ # ifdef __BIG_ENDIAN__ printf("__BIG_ENDIAN__ defined\n"); # define HOST_IS_LITTLE_ENDIAN 0 # endif # endif #endif #ifndef HOST_IS_LITTLE_ENDIAN /* default to big endian */ # define HOST_IS_LITTLE_ENDIAN 0 #endif dw=atoi(argv[1]); printf("bits @%p: %d (0x%x)\n%s\n", &dw, dw, dw, out_c(dw)); } char *out_c(unsigned int c) { char *p=s+15; do { *p--="01"[c&0x01]; c>>=1; } while ( p>=s ); return(s); }