#include <Bits.hh>
Public Methods | |
Bits_ (unsigned int N=0, bool Val=false) | |
Inits to hold N bits (default 0). More... | |
Bits_ (const Bits_ &Bits) | |
copy constructor. | |
Bits_ (const char *Str) | |
Inits by a string Str which should have the format "110101001", 0 for "false", 1 for "true", 1st char is MSB, last is LSB. More... | |
~Bits_ () | |
destructor. | |
Bits_& | operator= (const Bits_ &Rhs) |
assignment. | |
bool | operator== (const Bits_ &Other) const |
Two Bits_ arrays are equal if they have the same number of bits and all bits are set in the same way. | |
bool | operator!= (const Bits_ &Other) const |
Non-equality. | |
unsigned int | cno () const |
The number of uints used in storing the bit array. | |
bool | get_bit (unsigned int Idx) const |
get_bit(): returns the Boolean value of the Idx-th bit. More... | |
bool | set_bit (unsigned int Idx, bool Value=true) |
set_bit(): sets the Idx-th bit to Value (default is true). More... | |
void | set_values (bool Value=true) |
set_values(): sets all bits to Value (default is true). | |
unsigned int | len () const |
Returns the number of bits in the array. | |
unsigned int | len (unsigned int Len) |
len(Len): adjusts the size of the bit array to Len. More... | |
unsigned int | on_no () const |
Returns the number of bits that are set to true. | |
unsigned int | off_no () const |
Returns the number of bits that are set to false. | |
Bits_& | operator~ () |
The following overlaid operators (~,&,|,^) perform exactly the same bitwise operations as their standard counterparts. More... | |
Bits_& | operator &= (const Bits_ &Bits) |
Bits_& | operator|= (const Bits_ &Bits) |
Bits_& | operator^= (const Bits_ &Bits) |
Bits_ | operator & (const Bits_ &Bits) const |
Bits_ | operator| (const Bits_ &Bits) const |
Bits_ | operator^ (const Bits_ &Bits) const |
Bits_& | operator<<= (unsigned int Shift) |
The following operators (<<,<<=,>>,>>=) do exactly the same things as their original C counterparts. More... | |
Bits_& | operator>>= (unsigned int Shift) |
Bits_ | operator<< (unsigned int Shift) const |
Bits_ | operator>> (unsigned int Shift) const |
Protected Methods | |
unsigned int | zero_mask () const |
Static Protected Methods | |
unsigned int | uints_needed (unsigned int Bitno) |
hidden methods. | |
unsigned int | get_mask (unsigned int Idx, unsigned int &Offs) |
unsigned int* | alloc_arr (unsigned int Size, const unsigned int *Arr=NULL) |
Private Methods | |
unsigned int | read_dataline (istream &In, char *Buffer) |
Private Attributes | |
unsigned int* | B |
the bit array. | |
size_t | Cs |
size_t | Bs |
no. of uints and bits. | |
Static Private Attributes | |
const size_t | BITS_PER_CHAR |
bits per char. | |
const size_t | BITS_PER_UINT |
bits per unsigned int. | |
Friends | |
istream& | operator>> (istream &In, Bits_ &Bits) |
Read a bit array from stream In. More... | |
ostream& | operator<< (ostream &Out, const Bits_ &Bits) |
Writes a bit array to stream Out. |
Bits are stored in an array of unsigned ints. Individual bits can be set and tested and global bitwise Boolean operations can be performed.
Definition at line 42 of file Bits.hh.
|
Inits to hold N bits (default 0). Set all bits to Val (false by default). |
|
copy constructor.
|
|
Inits by a string Str which should have the format "110101001", 0 for "false", 1 for "true", 1st char is MSB, last is LSB. Any char other than '0' or '1' will elicit a warning and will be interpreted as "true". if Str==NULL or if it is the empty string "" then an empty object will be created. |
|
destructor.
|
|
assignment.
|
|
Two Bits_ arrays are equal if they have the same number of bits and all bits are set in the same way.
|
|
Non-equality.
|
|
The number of uints used in storing the bit array.
|
|
get_bit(): returns the Boolean value of the Idx-th bit. Throws Indexrangexc_ if Idx is out of range. Throws Emptyexc_ if the calling object is empty. |
|
set_bit(): sets the Idx-th bit to Value (default is true). Returns old value. Throws Indexrangexc_ if Idx is out of range. Throws Emptyexc_ if the calling object is empty. |
|
set_values(): sets all bits to Value (default is true).
|
|
Returns the number of bits in the array.
|
|
len(Len): adjusts the size of the bit array to Len. If Len==Bs, no action is taken, if Len<Bs then the tail of the array is lost, if Len>Bs then the tail of the new array will be filled with false values (0). Returns the old length. |
|
Returns the number of bits that are set to true.
|
|
Returns the number of bits that are set to false.
|
|
The following overlaid operators (~,&,|,^) perform exactly the same bitwise operations as their standard counterparts. The bit array sizes must be the same otherwise a Dimexc_ exception is thrown. |
|
|
|
|
|
|
|
|
|
|
|
|
|
The following operators (<<,<<=,>>,>>=) do exactly the same things as their original C counterparts. For << and <<=, 0 bits are shifted in at the right; for >> and >>=, 0 bits are shifted in from the left. Empty bit-vectors will be filled up with Shift 0-s. |
|
|
|
|
|
|
|
hidden methods.
|
|
|
|
|
|
|
|
|
|
Read a bit array from stream In. The ASCII format of a Bits_ object is:- ------------------------------------ 00000 00100110 [76..64] 00000000 00000000 00000000 00000000 [63..32] 00000011 11111111 11111111 11111111 [31..0] ==================================== |
|
Writes a bit array to stream Out.
|
|
bits per char.
|
|
bits per unsigned int.
|
|
the bit array.
|
|
|
|
no. of uints and bits.
|