00001
00002
00003
00004 #ifndef ENDIAN_H
00005 #define ENDIAN_H
00006
00007
00008 namespace endian
00009 {
00010 typedef unsigned short u16_t;
00011 typedef short s16_t;
00012 typedef unsigned int u32_t;
00013 typedef int s32_t;
00014
00015 template <typename T> T betoh (void const *f)
00016 {
00017 T t;
00018 unsigned char const *fp = (unsigned char const *) f;
00019 unsigned char *tp = (unsigned char *) &t;
00020
00021 fp += sizeof (T) - 1;
00022 for (unsigned i = 0; i < sizeof (T); i++)
00023 *(tp++) = *(fp--);
00024 return t;
00025 }
00026 };
00027
00028
00029 #endif