* Author: S. Piccardi
* May. 2003
*
- * $Id: endian.c,v 1.3 2003/08/16 18:11:24 piccardi Exp $
+ * $Id: endian.c,v 1.4 2003/08/16 18:22:25 piccardi Exp $
*
***************************************************************/
#include <stdio.h>
/*
* Variables definition
*/
- int i, val;
- char buf[sizeof(int)];
- int * int_ptr;
+ short magic, test;
+ char * ptr;
- val = 0xABCDEF01; /* endianess magic number */
- int_ptr = (int *) buf;
- *int_ptr = val;
- val = 0;
- for (i=0; i<sizeof(int); i++) {
- val = (val<<8) + buf[i];
- printf("i=%d, val=%x\n", i, buf[i]);
- }
- printf("Value %x\n", val);
- return 0;
+ magic = 0xABCD; /* endianess magic number */
+ ptr = (char *) &magic;
+ printf("Upper = %x\n", ptr[1]);
+ printf("Lower = %x\n", ptr[0]);
+ test = (ptr[1]<<8) + (ptr[0]&0xFF);
+ printf("magic=%x, test=%x\n", magic, test);
+ return (magic == test);
}