Hello there all,
I am enrolled in a Data Structures class and we are studying the structure called bitvector. It's a really interesting course... one that actually makes use of C++ other than doing some simple "Hello World" type programs assigned to us in the introductory course of C++.
Anyway, my question to you all is this. For those of you that do know, a bitvector can be manipulated in the bit level. I understand how to access at the bit level. You access the kth bit by:
1) Performing integer division by 8
2) Performing a "mask" at the kth bit
This is done in code like so:
Code:
void BitVector::Set(unsigned int index)
// make bit = 1
{
// Access the bit k, by integer dividing index by 8
// and shifting index % 8
unsigned byte = Array[index/8];
unsigned bit = Test(index);
}
where Test is:
Code:
int BitVector::Test(unsigned int index) const
// tests whether a bit is turned 'on' or 'off'
{
return (Array[ByteNumber(index)] & Mask(index)) != 0;
}
My question is now that you have accessed it, how do you manipulate at the bit level?? An explanation over code is much more appreciated. Thank you for your time.