home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / pub / users / Harry / Blitz / version-1-0 / BlitzSrc / endian.c < prev    next >
C/C++ Source or Header  |  2006-09-25  |  697b  |  26 lines

  1. #include <stdio.h>
  2. #include <strings.h>
  3.  
  4. int i;
  5. char * p;
  6.  
  7. main () {
  8.   printf ("This program tests whether this computer uses Big Endian or Little Endian byte ordering...\n");
  9.   i = 0x12345678;
  10.   printf ("The following line should print 0x12345678...\n");
  11.   printf ("        0x%08x\n", i);
  12.   printf ("This program stores 11, 22, 33, and 44 in sucessive bytes and then accesses it as a 4 byte integer.\n");
  13.   p = (char *) (& i);
  14.   *p = 0x11;
  15.   p++;
  16.   *p = 0x22;
  17.   p++;
  18.   *p = 0x33;
  19.   p++;
  20.   *p = 0x44;
  21.   printf ("Big Endian machines will print 0x11223344 next...\n");
  22.   printf ("Little Endian machines will print 0x44332211 next...\n");
  23.   printf ("        0x%08x\n", i);
  24.   printf ("Good bye\n");
  25. }
  26.