S
Sam Smith
I've just started to play around with boost in general and the
dynamic_bitset in particular. I want to use the dynamic_bitset to hold an
array of data as stream of bits:
unsigned char data[5] = {211,14,97,42,31};
boost::dynamic_bitset<unsigned char> bitbuf(data,&data[5]);
Now, another issue has surfaced. When iterating the bitset I see that the
bits
are stored in a "weird" format (at least it is weird to me)?!
for (int i=0; i<5*8; ++i)
{
bool bit_i = bitbuf;
std::cout << bit_i;
}
Instead of the expected sequence:
1101001100001110011000010010101000011111
the loop prints:
1100101101110000100001100101010011111000
I.e. each byte has its bits in the reversed order! As a newbie it is not
obvious to me why this is so... And the confusion is total after this:
std::cout << bitbuf;
which decides to print the sequence:
0001111100101010011000010000111011010011
Please help me figure the rationale behind this out!
Another issue I have is how to extract the bits!?
Is it only possible to extract one bit (using operator[]) or all bits (using
to_block_range)?!?!? I'd much rather extract a range of bits starting at a
specified bit position and a given number of bits:
unsigned short value = bitbuf.get(3,12); // Extract 12 bits starting at
pos 3
Thanks in advance!
dynamic_bitset in particular. I want to use the dynamic_bitset to hold an
array of data as stream of bits:
unsigned char data[5] = {211,14,97,42,31};
boost::dynamic_bitset<unsigned char> bitbuf(data,&data[5]);
Now, another issue has surfaced. When iterating the bitset I see that the
bits
are stored in a "weird" format (at least it is weird to me)?!
for (int i=0; i<5*8; ++i)
{
bool bit_i = bitbuf;
std::cout << bit_i;
}
Instead of the expected sequence:
1101001100001110011000010010101000011111
the loop prints:
1100101101110000100001100101010011111000
I.e. each byte has its bits in the reversed order! As a newbie it is not
obvious to me why this is so... And the confusion is total after this:
std::cout << bitbuf;
which decides to print the sequence:
0001111100101010011000010000111011010011
Please help me figure the rationale behind this out!
Another issue I have is how to extract the bits!?
Is it only possible to extract one bit (using operator[]) or all bits (using
to_block_range)?!?!? I'd much rather extract a range of bits starting at a
specified bit position and a given number of bits:
unsigned short value = bitbuf.get(3,12); // Extract 12 bits starting at
pos 3
Thanks in advance!