a C++ bitset class which allows set bit-number during run time. As know, the standard C++ doesn't support init a bitset class during runtime using a runtime result.
-
set(const int bitpos) - set the given bitpos to 1, if the parameter is -1, set all bit to 1
-
reset(const int bitpos, const bool value) - set the given bitpos to the given value (0 or 1)
-
test(const int bitpos) - try to get the bit value, true for 1, and false for 0
-
operator(const int bitpos) - the same as the function test(..)
-
print() - output the bitset, the output format is controlled by function set_output_format(...)
-
set_output_format(const int cluster_bit_size) - set output format
-
operator[] - set to true or set to false
please contact [email protected] or xgzhang at seu.edu.cn if you have any question to use the class.
int main()
{
bitset_ex bs(7);
bs.set();
bs.set_output_format(4);
bs.print();
bs.set(3);
bs.reset(2);
bs.reset(4);
bs.print();
bs[2] = true;
bs[3] = false;
bs.print();
if(bs.test(2))
cout<<"good"<<endl;
else
cout<<"bad"<<endl;
}