StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bits.hh
1 //
2 // Pibero Djawotho <pibero@tamu.edu>
3 // Texas A&M University
4 // 14 Jan 2011
5 //
6 
7 #ifndef BITS_HH
8 #define BITS_HH
9 #include<stdio.h>
10 // returns value of bit from x at position pos
11 inline int btest(int x, int pos) { return x >> pos & 1; }
12 
13 // returns n bits from x starting at position pos
14 inline int getbits(int x, int pos, int n) { return x >> pos & ~(~0 << n); }
15 
16 // OR x with value starting at position pos
17 inline void setbits(int& x, int pos, int value) { x |= value << pos; }
18 
19 #endif // BITS_HH