Reputation: 29353
std::string charBuff = "11010";
dbitset = boost::dynamic_bitset<unsigned char> (charBuff);
for (boost::dynamic_bitset<>::size_type i = 0; i < dbitset.size(); ++i) {
std::cout << dbitset[i];
}
It prints from the LSB to MSB. Output: 01011.
What should I do to so that bitset is printed correctly. I can reverse the character buffer which I am aware of :)
Upvotes: 0
Views: 1205
Reputation: 111120
<unsigned car>
Should be:
<unsigned char>
What is buffer
? Shouldn't you use charBuff
?
Use the operator<<
overload for dynamic_bitset
s to achieve what you want. Here's a simplified solution:
#include <iostream>
#include <string>
#include <boost/dynamic_bitset.hpp>
int main()
{
std::string charBuff("11010");
boost::dynamic_bitset<> dbitset(charBuff);
/* print LSB to MSB, in order */
for (boost::dynamic_bitset<>::size_type i = 0;
i < dbitset.size(); ++i) {
std::cout << dbitset[i];
}
std::cout << std::endl;
/* print bits in the order you want */
std::cout << dbitset << std::endl;
return 0;
}
Upvotes: 1