TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BIN.h
Go to the documentation of this file.
1 #ifndef G3D_BIN_h
2 #define G3D_BIN_h
3 
4 #define _BIT(N, K) (((N >> (3*K)) & 1) << K)
5 
6 #define _OCT_CODED_BIN(N) \
7  (_BIT(N, 0) | _BIT(N, 1) | _BIT(N, 2) | _BIT(N, 3) | \
8  _BIT(N, 4) | _BIT(N, 5) | _BIT(N, 6) | _BIT(N, 7) | \
9  _BIT(N, | _BIT(N, 9) | _BIT(N, 10))
10 
23 #define BIN11(N) _OCT_CODED_BIN(0 ## N ## UL)
24 
25 
26 
27 /* turn a numeric literal into a hex constant
28  (avoids problems with leading zeroes)
29  8-bit constants max value 0x11111111, always fits in unsigned long
30 */
31 #define HEX__(n) 0x##n##LU
32 
33 /* 8-bit conversion function */
34 #define B8__(x) ((x&0x0000000FLU)?1:0) \
35 +((x&0x000000F0LU)?2:0) \
36 +((x&0x00000F00LU)?4:0) \
37 +((x&0x0000F000LU)?8:0) \
38 +((x&0x000F0000LU)?16:0) \
39 +((x&0x00F00000LU)?32:0) \
40 +((x&0x0F000000LU)?64:0) \
41 +((x&0xF0000000LU)?128:0)
42 
56 #define BIN8(d) ((unsigned char)B8__(HEX__(d)))
57 
70 #define BIN16(dmsb, dlsb) (((unsigned short)BIN8(dmsb) << 8) + BIN8(dlsb))
71 
72 
86 #define BIN32(dmsb,db2,db3,dlsb) \
87  (((unsigned long)BIN8(dmsb) << 24) + \
88  ((unsigned long)BIN8(db2) << 16) + \
89  ((unsigned long)BIN8(db3) << 8) + \
90  BIN8(dlsb))
91 
92 #endif