Following:
char c = 'A';
std::bitset<8> b(c);
must work.
See http://ideone.com/PtSFvz
Converting an arbitrary length stringto is bitsetmore difficult, if at all possible. The size of the bit set must be known at compile time, so there really is no way to convert a string to one.
However, if you know the length of the string at compile time (or you can bind it at compile time), you can do something like:
const size_t N = 50;
bitset<N * 8> b;
for (int i = 0; i < str.length(); ++i) {
char c = s[i];
for (int j = 7; j >= 0 && c; --j) {
if (c & 0x1) {
b.set(8 * i + j);
}
c >>= 1;
}
}
, , .