std::bitset
has a to_string()
method for serializing as a char
-based string of 1
s and 0
s. Obviously, this uses a single 8 bit char
for each bit in the bitset, making the serialized representation 8 times longer than necessary.
I want to store the bitset in a binary representation to save space. The to_ulong()
method is relevant only when there are less than 32 bits in my bitset. I have hundreds.
I'm not sure I want to use memcpy()
/std::copy()
on the object (address) itself, as that assumes the object is a POD.
The API does not seem to provide a handle to the internal array representation from which I could have taken the address.
I would also like the option to deserialize the bitset from the binary representation.
How can I do this?
See Question&Answers more detail:os