Back to the WFC main page

CBitArray

$Revision: 19 $

Description

This class treats bits like they were an integral type.

Constructors

CBitArray()
CBitArray( DWORD initial_size )
CBitArray( const CBitArray& source )
CBitArray( const CByteArray& source )
Constructs this object.

Methods

void Add( DWORD bit_to_add, DWORD count = 1 )
Appends a new bit to the array. If bit_to_add is not zero, a 1-bit is added.
void AddByte( BYTE byte_to_add )
Appends byte (8 bits) to the array.
void AddValue( DWORD value_to_add, DWORD number_of_bits_in_value )
Appends a a value to the array. You specify how many bits are in value_to_add (up to 32).
void Append( const CBitArray& source  )
void Append( const BYTE * data, DWORD number_of_bytes )
Appends a whole bunch of bits to the array.
void Complement( void )
Turns every zero into a one and every one into a zero in the array.
void Copy( const CBitArray& source )
void Copy( const CByteArray& source )
Copies bits from the specified source.
void CopyTo( CByteArray& destination )
void CopyTo( CDWordArray& destination )
Exports the bits to the destination supplied.
BOOL Find( const CBitArray& value, DWORD& found_at, DWORD starting_at = 0 ) const
BOOL Find( DWORD value, DWORD number_of_bits_in_value, DWORD& found_at, DWORD starting_at = 0 ) const
Searches for a bit pattern in the array. If it returns TRUE, found_at will be filled with the index where the pattern begins.
void FreeExtra( void )
Compresses the memory used to store the bits.
DWORD GetAt( DWORD index ) const
Returns a 1 if the bit at that index is not zero. It will return 0 if that bit is a zero. If index is something wacky (i.e. passed the end of the array), it will return 0.
DWORD GetNumberOfOnes( void ) const
Returns the number of bits that are 1.
DWORD GetNumberOfZeroes( void ) const
Returns the number of bits that are 0.
DWORD GetSize( void ) const
Returns the number of bits in the array.
DWORD GetUpperBound( void ) const
Returns the current upper bound of this array. Because array indexes are zero-based, this function returns a value 1 less than GetSize().
DWORD GetValue( DWORD index, DWORD length ) const
Returns the value at the given location.
void InsertAt( DWORD index, DWORD value )
Inserts a single bit at the given index.
CBitArray Left( DWORD number_of_bits ) const
Returns the left-most number_of_bits.
void LeftTrim( DWORD number_of_bits )
Trims the number_of_bits from the beginning of the array.
CBitArray Mid( DWORD starting_at_index, DWORD number_of_bits ) const
Returns number_of_bits beginning at starting_at_index.
void RemoveAll( void )
Clears the array. It removes all bits.
void RemoveAt( DWORD index )
Removes a single bit at the given index.
CBitArray Right( DWORD number_of_bits )
Returns the last number_of_bits in the array.
void RightTrim( DWORD number_of_bits )
Removes the last number_of_bits from the array.
void Serialize( CArchive& archive )
After all, we are a CObject...
void SetAll( DWORD value )
Sets all of the bits in the array to value.
void SetAt( DWORD index, DWORD value )
Sets the bits at the given index to value.
void SetSize( DWORD size )
Allocates enough memory to hold size bits.
void SetValue( DWORD index, DWORD value, DWORD length )
Beginning at index, the bits in value will replace the bits in the array for length number of bits.

Operators

CBitArray& operator = ( const CBitArray& source )
CBitArray& operator = ( const CByteArray& source )
Basically calls Copy().
CBitArray& operator += ( const CBitArray& source )
CBitArray& operator += ( const CByteArray& source )
Basically calls Append().
DWORD operator [] ( int index ) const
Calls GetAt().

Example

#include <wfc.h>

int _tmain( int number_of_command_line_arguments, LPCTSTR command_line_arguments[] )
{
   WFCTRACEINIT( TEXT( "_tmain()" ) );

   CBitArray bits;

   bits.Add( 0x55 );

   _tprintf( TEXT( "Bit number 7 is %d\n", (int) bits.GetAt( 7 ) );

   bits.SetAt( 7, 0 ); // Turn bit 7 off
}

Copyright, 2000, Samuel R. Blackburn
$Workfile: CBitArray.cpp $
$Modtime: 1/17/00 8:57a $