ATLAS Offline Software
Loading...
Searching...
No Matches
BitOp.h
Go to the documentation of this file.
1// Dear emacs, this is -*- c++ -*-
2/*
3 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
4*/
5#ifndef TRIGT1INTERFACES_BITOP_H
6#define TRIGT1INTERFACES_BITOP_H
7
8// STL includes:
9#include <string>
10
24class BitOp {
25
26public:
32 static void printBin( unsigned int uintValue ) { printBinN( uintValue, 31 ); }
33 static void printBin( int intValue ) { printBinN( intValue, 31 ); }
34 static void printBinN( unsigned int uintValue, int nbits );
35 static void printBinN( int intValue, int nbits );
36
38 static const std::string printBits( const int value, const int startbit,
39 const int endbit );
40
47 inline static bool isSet( const unsigned int *uintValue, int bit ) {
48 return ( *uintValue == ( *uintValue | ( 1 << bit ) ) );
49 }
50
51 inline static bool isSet( const int *intValue, int bit ) {
52 return ( *intValue == ( *intValue | ( 1 << bit ) ) );
53 }
54
59 inline static void setBit( unsigned int *uintValue, int bit ) {
60 *uintValue |= ( 1 << bit );
61 }
62 inline static void setBit( int *intValue, int bit ) {
63 *intValue |= ( 1 << bit );
64 }
65
70 inline static void clearBit( unsigned int *uintValue, int bit ) {
71 *uintValue |= ( 1 << bit ); *uintValue ^= ( 1 << bit );
72 }
73 inline static void clearBit( int *intValue, int bit ) {
74 *intValue |= ( 1 << bit ); *intValue ^= ( 1 << bit );
75 }
76
83 inline static void sImposeNBits( unsigned int *uintValue, int stbit, int wrd ) {
84 *uintValue |= ( wrd << stbit );
85 }
86 inline static void sImposeNBits( int *intValue, int stbit, int wrd ) {
87 *intValue |= ( wrd << stbit );
88 }
89 inline static void sImposeNBits( unsigned int *uintValue, int stbit,
90 unsigned int wrd ) {
91 *uintValue |= ( wrd << stbit );
92 }
93 inline static void sImposeNBits( int *intValue, int stbit, unsigned int wrd ) {
94 *intValue |= ( wrd << stbit );
95 }
96
98 static unsigned int alignBits( int value, int startbit, int endbit );
100 static unsigned int createMask( int startbit, int endbit );
101
106 static unsigned int getValue( const unsigned int * uintValue,
107 const unsigned int mask );
108
109}; // class BitOp
110
111#endif // TRIGT1INTERFACES_BITOP_H
Utility class for integer bit operations.
Definition BitOp.h:24
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
Definition BitOp.cxx:47
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
static void printBin(int intValue)
Definition BitOp.h:33
static void sImposeNBits(unsigned int *uintValue, int stbit, unsigned int wrd)
Definition BitOp.h:89
static unsigned int alignBits(int value, int startbit, int endbit)
align given bits using start and end position into 32 bits
Definition BitOp.cxx:67
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.
Definition BitOp.h:83
static void clearBit(unsigned int *uintValue, int bit)
Clear the given bit in the given integer.
Definition BitOp.h:70
static void setBit(int *intValue, int bit)
Definition BitOp.h:62
static void sImposeNBits(int *intValue, int stbit, unsigned int wrd)
Definition BitOp.h:93
static void setBit(unsigned int *uintValue, int bit)
Set the given bit in the given unsigned int or int value.
Definition BitOp.h:59
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
static void sImposeNBits(int *intValue, int stbit, int wrd)
Definition BitOp.h:86
static void printBin(unsigned int uintValue)
Utitlity function to print out the binary representation of an input int or unsigned int value.
Definition BitOp.h:32
static bool isSet(const int *intValue, int bit)
Definition BitOp.h:51
static void printBinN(unsigned int uintValue, int nbits)
Definition BitOp.cxx:19
static const std::string printBits(const int value, const int startbit, const int endbit)
print selected bit range into string
Definition BitOp.cxx:100
static void clearBit(int *intValue, int bit)
Definition BitOp.h:73