#include "hbitman.h" #include #include using namespace std; //_HADES_CLASS_DESCRIPTION /////////////////////////////////////////////////////////// // HBitMan // // library of static functions // look here for auxiliary functions for: // bit manipulations. // // The direct bit functions can be used static. // Bit counting starts at 0. 0 represents the lowest bit. // The function do not check the range! Take care you // stay inside the range. // For the bit functions using names see the following // example: // // bits in Integer: // 11 // 10 tofrec (no sign) // 9 // 8 // 7. charge -1 0 1 (sign) // 6. // 5. system 0-3 (no sign) // 4........ // 3........sector 0-7 (no sign) // 2........ // 1........ // // // allocate the word map. Bit are allocated // // in the order of declaration. word width include the // // extra bit for sign if sign is specified! // HBitMan bitman; // bitman.createWord("sector",3,kFALSE); // bitman.createWord("sys" ,3,kFALSE); // bitman.createWord("charge",3,kTRUE); // 2bits+sign = 3 // bitman.createWord("tofrec",3,kFALSE); // bitman.init(); // // // // UInt_t common = 0; // flag integer // // // set values // bitman.setWord(common,"sector",3); // bitman.setWord(common,"sys" ,1); // bitman.setWord(common,"charge",-1); // bitman.setWord(common,"tofrec",3); // // // bitman.printBits(common); // print binary representation // cout<= 0; i --){ cout<< ((data >> i) & 0x1) <> bit ) & 0x01 ; } void HBitMan::setWord(UInt_t &data,Int_t num,Int_t width, Int_t val,Bool_t sign){ // add data starting at bit num (from low) with n bits width // width includes the sign bit if sign is kTRUE. if(sign){ data = ( ((abs(val) & ((0x1<<(width-1))-1)) << num) | data ); // first set word without sign data |= ( ( (val < 0) & 0x01) << (num+width) ); // sign: highest bit of word=1 for negative } else { data = ( ((val& ((0x1<<(width))-1)) << num) | data ); } } void HBitMan::unsetWord(UInt_t &data,Int_t num,Int_t width){ // unset data starting at bit num (from low) with n bits width data = ~((((0x1<> (num+width) ) & 0x01) == 1){ return -((data >> num ) & ((0x1<<(width-1))-1)); } else { return ((data >> num ) & ((0x1<<(width-1))-1)); } } else { return (data >> num ) & ((0x1<