helpers.h

Go to the documentation of this file.
00001 #ifndef HELPERS_H_
00002 #define HELPERS_H_
00003 
00004 #include <inttypes.h>
00005 
00006 #if defined(__APPLE_CC__)
00007 #define IS_BIG_ENDIAN
00008 #endif
00009 
00010 #if defined WORDS_BIGENDIAN || defined IS_BIG_ENDIAN
00011 // We must ensure that the entity is unsigned
00012 // otherwise, if it is signed/negative, the MSB will be
00013 // propagated when we shift
00014 #define LITTLE_TO_NATIVE16(x) (((((uint16_t) x) & 0xFF) << 8) | \
00015                                (((uint16_t) x) >> 8))
00016 #define LITTLE_TO_NATIVE32(x) (((((uint32_t) x) & 0xFF) << 24) | \
00017                                (((((uint32_t) x) >> 8) & 0xFF) << 16) | \
00018                                (((((uint32_t) x) >> 16) & 0xFF) << 8) | \
00019                                (((uint32_t) x) >> 24))
00020 
00021 #define BIG_TO_NATIVE16(x) x
00022 #define BIG_TO_NATIVE32(x) x
00023 #else
00024 #define LITTLE_TO_NATIVE16(x) x
00025 #define LITTLE_TO_NATIVE32(x) x
00026 #define BIG_TO_NATIVE16(x) (((((uint16_t) x) & 0xFF) << 8) | \
00027                                (((uint16_t) x) >> 8))
00028 #define BIG_TO_NATIVE32(x) (((((uint32_t) x) & 0xFF) << 24) | \
00029                                (((((uint32_t) x) >> 8) & 0xFF) << 16) | \
00030                                (((((uint32_t) x) >> 16) & 0xFF) << 8) | \
00031                                (((uint32_t) x) >> 24))
00032 
00033 
00034 #endif
00035 
00036 
00037 
00038 #endif

Generated on Mon Jan 23 19:44:27 2006 for Visualization by  doxygen 1.4.6