ATLAS Offline Software
Static Public Member Functions | List of all members
BitOp Class Reference

Utility class for integer bit operations. More...

#include <BitOp.h>

Collaboration diagram for BitOp:

Static Public Member Functions

static void printBin (unsigned int uintValue)
 Utitlity function to print out the binary representation of an input int or unsigned int value. More...
 
static void printBin (int intValue)
 
static void printBinN (unsigned int uintValue, int nbits)
 
static void printBinN (int intValue, int nbits)
 
static const std::string printBits (const int value, const int startbit, const int endbit)
 print selected bit range into string More...
 
static bool isSet (const unsigned int *uintValue, int bit)
 Check if a the given bit in the given unsigned int or int value is set. More...
 
static bool isSet (const int *intValue, int bit)
 
static void setBit (unsigned int *uintValue, int bit)
 Set the given bit in the given unsigned int or int value. More...
 
static void setBit (int *intValue, int bit)
 
static void clearBit (unsigned int *uintValue, int bit)
 Clear the given bit in the given integer. More...
 
static void clearBit (int *intValue, int bit)
 
static void sImposeNBits (unsigned int *uintValue, int stbit, int wrd)
 Superimpose the given integer wrd starting at bit stbit onto integer or unsigned interger value. More...
 
static void sImposeNBits (int *intValue, int stbit, int wrd)
 
static void sImposeNBits (unsigned int *uintValue, int stbit, unsigned int wrd)
 
static void sImposeNBits (int *intValue, int stbit, unsigned int wrd)
 
static unsigned int alignBits (int value, int startbit, int endbit)
 align given bits using start and end position into 32 bits More...
 
static unsigned int createMask (int startbit, int endbit)
 create a 32 bit long mask with 1s from given start to end position More...
 
static unsigned int getValue (const unsigned int *uintValue, const unsigned int mask)
 get the value in the input word represented by a bit pattern given as a bitmask More...
 

Detailed Description

Utility class for integer bit operations.

   This is a utility class for integer bit operations.
   Operations that set or unset bits are done using 
   pointers and are inline, as they need to be fast.
   The print methods are not time-critical.
Author
Thorsten Wengler
Revision
187728
Date
2009-05-27 18:18:06 +0200 (Wed, 27 May 2009)

Definition at line 24 of file BitOp.h.

Member Function Documentation

◆ alignBits()

unsigned int BitOp::alignBits ( int  value,
int  startbit,
int  endbit 
)
static

align given bits using start and end position into 32 bits

Definition at line 67 of file BitOp.cxx.

68 {
69  int ostart = std::min( startbit, endbit );
70  int oend = std::max( startbit, endbit );
71  unsigned int start = std::max( ostart, 0 );
72  unsigned int end = std::min( oend, 32 );
73 
74  unsigned int result = value;
75  if ( ostart < 0 ) {
76  result >>= std::abs( ostart );
77  } else {
78  result <<= ostart;
79  }
80  result &= createMask( start, end );
81 
82  return result;
83 }

◆ clearBit() [1/2]

static void BitOp::clearBit ( int *  intValue,
int  bit 
)
inlinestatic

Definition at line 73 of file BitOp.h.

73  {
74  *intValue |= ( 1 << bit ); *intValue ^= ( 1 << bit );
75  }

◆ clearBit() [2/2]

static void BitOp::clearBit ( unsigned int *  uintValue,
int  bit 
)
inlinestatic

Clear the given bit in the given integer.

Uses pointer to the object and is inline.

Definition at line 70 of file BitOp.h.

70  {
71  *uintValue |= ( 1 << bit ); *uintValue ^= ( 1 << bit );
72  }

◆ createMask()

unsigned int BitOp::createMask ( int  startbit,
int  endbit 
)
static

create a 32 bit long mask with 1s from given start to end position

Definition at line 85 of file BitOp.cxx.

86 {
87  unsigned int start = std::min( std::max( startbit, 0 ), std::max( endbit, 0 ) );
88  unsigned int end = std::max( std::min( startbit, 32 ), std::min( endbit, 32 ) );
89 
90  unsigned int result = 0;
91  for( unsigned int i = 0; i <= ( end - start ); ++i ) {
92  result <<= 1;
93  result |= 1;
94  }
95  result <<= start;
96 
97  return result;
98 }

◆ getValue()

unsigned int BitOp::getValue ( const unsigned int *  uintValue,
const unsigned int  mask 
)
static

get the value in the input word represented by a bit pattern given as a bitmask

Definition at line 47 of file BitOp.cxx.

48  {
49 
50  unsigned int result;
51  unsigned int maskcopy;
52  // make a copy of the mask, because a mask is a mask and
53  // one should stay a mask (i.e. should be something constant!)
54  maskcopy = mask;
55  result = *uintValue & mask;
56  if ( mask != 0 ) {
57  while ( ( maskcopy & 0x00000001 ) == 0 ) {
58  maskcopy = maskcopy >> 1;
59  result = result >> 1;
60  }
61  }
62 
63  return result;
64 
65 }

◆ isSet() [1/2]

static bool BitOp::isSet ( const int *  intValue,
int  bit 
)
inlinestatic

Definition at line 51 of file BitOp.h.

51  {
52  return ( *intValue == ( *intValue | ( 1 << bit ) ) );
53  }

◆ isSet() [2/2]

static bool BitOp::isSet ( const unsigned int *  uintValue,
int  bit 
)
inlinestatic

Check if a the given bit in the given unsigned int or int value is set.

True if yes. Uses pointer to the obejct and is inline. Does not change the initial value given to the function.

Definition at line 47 of file BitOp.h.

47  {
48  return ( *uintValue == ( *uintValue | ( 1 << bit ) ) );
49  }

◆ printBin() [1/2]

static void BitOp::printBin ( int  intValue)
inlinestatic

Definition at line 33 of file BitOp.h.

33 { printBinN( intValue, 31 ); }

◆ printBin() [2/2]

static void BitOp::printBin ( unsigned int  uintValue)
inlinestatic

Utitlity function to print out the binary representation of an input int or unsigned int value.

Does not need to be fast.

Definition at line 32 of file BitOp.h.

32 { printBinN( uintValue, 31 ); }

◆ printBinN() [1/2]

void BitOp::printBinN ( int  intValue,
int  nbits 
)
static

Definition at line 33 of file BitOp.cxx.

33  {
34 
35  std::string resultString( "" );
36  for ( int i = nbits; i >= 0; i-- ) {
37  if ( intValue & ( 1u << i ) ) {
38  resultString += "1";
39  } else {
40  resultString += "0";
41  }
42  if ( ( i % 4 ) == 0 ) resultString += " ";
43  }
44 
45 }

◆ printBinN() [2/2]

void BitOp::printBinN ( unsigned int  uintValue,
int  nbits 
)
static

Definition at line 19 of file BitOp.cxx.

19  {
20 
21  std::string resultString( "" );
22  for ( int i = nbits; i >= 0; i-- ) {
23  if ( uintValue & ( 1u << i ) ) {
24  resultString += "1";
25  } else {
26  resultString += "0";
27  }
28  if ( ( i % 4 ) == 0 ) resultString += " ";
29  }
30 
31 }

◆ printBits()

const std::string BitOp::printBits ( const int  value,
const int  startbit,
const int  endbit 
)
static

print selected bit range into string

Definition at line 100 of file BitOp.cxx.

101 {
102  int ostart = std::min( startbit, endbit );
103  int oend = std::max( startbit, endbit );
104  unsigned int start = std::max( ostart, 0 );
105  unsigned int end = std::min( oend, 32 );
106 
107  std::ostringstream s;
108 
109  for( unsigned int i = start; i <= end; ++i ) {
110  if ( isSet(&value, i) ) {
111  s << "1";
112  } else {
113  s << "0";
114  }
115  }
116 
117  return s.str();
118 }

◆ setBit() [1/2]

static void BitOp::setBit ( int *  intValue,
int  bit 
)
inlinestatic

Definition at line 62 of file BitOp.h.

62  {
63  *intValue |= ( 1 << bit );
64  }

◆ setBit() [2/2]

static void BitOp::setBit ( unsigned int *  uintValue,
int  bit 
)
inlinestatic

Set the given bit in the given unsigned int or int value.

Uses pointer to the object and is inline.

Definition at line 59 of file BitOp.h.

59  {
60  *uintValue |= ( 1 << bit );
61  }

◆ sImposeNBits() [1/4]

static void BitOp::sImposeNBits ( int *  intValue,
int  stbit,
int  wrd 
)
inlinestatic

Definition at line 86 of file BitOp.h.

86  {
87  *intValue |= ( wrd << stbit );
88  }

◆ sImposeNBits() [2/4]

static void BitOp::sImposeNBits ( int *  intValue,
int  stbit,
unsigned int  wrd 
)
inlinestatic

Definition at line 93 of file BitOp.h.

93  {
94  *intValue |= ( wrd << stbit );
95  }

◆ sImposeNBits() [3/4]

static void BitOp::sImposeNBits ( unsigned int *  uintValue,
int  stbit,
int  wrd 
)
inlinestatic

Superimpose the given integer wrd starting at bit stbit onto integer or unsigned interger value.

Uses pointer to the object and is inline. !! Bits already set in value are not reset !!

Definition at line 83 of file BitOp.h.

83  {
84  *uintValue |= ( wrd << stbit );
85  }

◆ sImposeNBits() [4/4]

static void BitOp::sImposeNBits ( unsigned int *  uintValue,
int  stbit,
unsigned int  wrd 
)
inlinestatic

Definition at line 89 of file BitOp.h.

90  {
91  *uintValue |= ( wrd << stbit );
92  }

The documentation for this class was generated from the following files:
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
get_generator_info.result
result
Definition: get_generator_info.py:21
max
#define max(a, b)
Definition: cfImp.cxx:41
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
athena.value
value
Definition: athena.py:124
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
lumiFormat.i
int i
Definition: lumiFormat.py:85
BitOp::printBinN
static void printBinN(unsigned int uintValue, int nbits)
Definition: BitOp.cxx:19
min
#define min(a, b)
Definition: cfImp.cxx:40
BitOp::isSet
static bool isSet(const unsigned int *uintValue, int bit)
Check if a the given bit in the given unsigned int or int value is set.
Definition: BitOp.h:47
BitOp::createMask
static unsigned int createMask(int startbit, int endbit)
create a 32 bit long mask with 1s from given start to end position
Definition: BitOp.cxx:85