aboutsummaryrefslogtreecommitdiff
path: root/endian.h
diff options
context:
space:
mode:
authorAlex Marshall <SquidMan72@gmail.com>2009-01-27 15:26:45 -0800
committerAlex Marshall <SquidMan72@gmail.com>2009-01-27 15:26:45 -0800
commit93a6d0d65a83fb2aa56696534b66f46c4e214940 (patch)
treea26bfcf341f213c1c20bb58d5c67ad71480d6141 /endian.h
Initial commit
Diffstat (limited to 'endian.h')
-rwxr-xr-xendian.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/endian.h b/endian.h
new file mode 100755
index 0000000..4c12e6b
--- /dev/null
+++ b/endian.h
@@ -0,0 +1,38 @@
+#ifndef _ENDIAN_H_
+#define _ENDIAN_H_
+
+#include "types.h"
+
+//#define be16(x) ((x>>8)|(x<<8))
+//#define be32(x) ((x>>24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x<<24))
+//#define be64(x) ((x>>56)|((x<<40)&(u64)0x00FF000000000000)|((x<<24)&(u64)0x0000FF0000000000)|((x<<8)&(u64)0x000000FF00000000)|((x>>8)&(u64)0x00000000FF000000)|((x>>24)&(u64)0x0000000000FF0000)|((x<<40)&(u64)0x000000000000FF00)|(x<<56))
+
+u16 be16(u16 x)
+{
+ return (x>>8) |
+ (x<<8);
+}
+
+u32 be32(u32 x)
+{
+ return (x>>24) |
+ ((x<<8) & 0x00FF0000) |
+ ((x>>8) & 0x0000FF00) |
+ (x<<24);
+}
+
+// __int64 for MSVC, "long long" for gcc
+u64 be64(u64 x)
+{
+ return (x>>56) |
+ ((x<<40) & (u64)0x00FF000000000000) |
+ ((x<<24) & (u64)0x0000FF0000000000) |
+ ((x<<8) & (u64)0x000000FF00000000) |
+ ((x>>8) & (u64)0x00000000FF000000) |
+ ((x>>24) & (u64)0x0000000000FF0000) |
+ ((x>>40) & (u64)0x000000000000FF00) |
+ (x<<56);
+}
+
+#endif //_ENDIAN_H_
+