StRoot
1
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
StSpinPool
StFmsTriggerMaker
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
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
// Reverse bits
20
inline
int
reversebit(
int
x,
int
max=31) {
21
int
y=0;
22
for
(
int
i=0; i<max; i++) y += ((x >> i) & 1) << (max-i-1);
23
return
y;
24
}
25
#endif // BITS_HH
Generated by
1.8.5