#include <BitVector.hpp>
Public Methods | |
BitVector () | |
BitVector (UCHAR *init, int size=8) | |
BitVector (char *binary) | |
virtual | ~BitVector () |
void | set (int bit) |
void | clear (int bit) |
int | read (int bit) |
int | bits () |
void | bits (int sz) |
void | print (const char *msg="") |
Private Attributes | |
UCHAR * | bytes |
int | Bits |
int | numBytes |
|
Definition at line 9 of file BitVector.cpp. |
|
Definition at line 13 of file BitVector.cpp. 00014 : numBytes( size ), Bits( numBytes * CHAR_BIT ) 00015 { 00016 bytes = (UCHAR*)calloc(numBytes, 1); 00017 assert( bytes ); 00018 00019 if ( init == NULL ) return; // Default to all 0 00020 00021 // Translate from bytes into bit sequence: 00022 for( int index = 0; index < numBytes; index++) 00023 for( int offset = 0; offset < CHAR_BIT; offset++) 00024 if ( init[index] & (highbit >> offset) ) 00025 set( index * CHAR_BIT + offset ); 00026 } |
|
Definition at line 28 of file BitVector.cpp. 00028 { 00029 Bits = strlen( binary ); 00030 numBytes = Bits / CHAR_BIT; 00031 00032 // If there's a remainder, add 1 byte: 00033 if ( Bits % CHAR_BIT ) numBytes++; 00034 00035 bytes = (unsigned char*)calloc(numBytes, 1); 00036 assert(bytes); 00037 00038 for(int i = 0; i < Bits; i++) 00039 if (binary[i] == '1') set(i); 00040 } |
|
Definition at line 42 of file BitVector.cpp. 00042 { 00043 free(bytes); 00044 } |
|
Definition at line 72 of file BitVector.cpp. 00072 { 00073 int oldsize = Bits; 00074 Bits = size; 00075 numBytes = Bits / CHAR_BIT; 00076 00077 // If there's a remainder, add 1 byte: 00078 if ( Bits % CHAR_BIT ) numBytes++; 00079 00080 void* v = realloc(bytes, numBytes); 00081 assert(v); 00082 00083 bytes = (unsigned char*)v; 00084 00085 for(int i = oldsize; i < Bits; i++) 00086 clear(i); // Erase additional bits 00087 } |
|
Definition at line 70 of file BitVector.cpp. 00070 { return Bits; } |
|
Definition at line 62 of file BitVector.cpp. Referenced by bits().
|
|
Definition at line 89 of file BitVector.cpp. |
|
Definition at line 54 of file BitVector.cpp. Referenced by print().
|
|
Definition at line 46 of file BitVector.cpp. Referenced by BitVector().
|
|
Definition at line 33 of file BitVector.hpp. |
|
Definition at line 32 of file BitVector.hpp. |
|
Definition at line 34 of file BitVector.hpp. |