Reverting a Bitset

Hey there,
You can create a bitset like so:
1
2
3
4
5
bitset<16>((int)10);
// or...
bitset<16>((char)'H');
// or...
bitset<16>((string)"Boosh"); 


But, there's no way to get back the original int, char or string value from that same bitset is there?
Do you mean without knowing which of the three it was?
line 1 is easy.
unsigned long val = bs.to_ulong(); // Will give you the value of 10

Line 3 requires that you know that an ASCII value was stored if you want to convert it back to a char value.

Line 5 makes no sense. You can initialize a bitset from a string containing 0s and 1s and return it back to a string of 0s and 1s using to_string(), but to use an argument of arbitrary characters makes no sense.



Thanks for your help

Topic archived. No new replies allowed.