I need to extact bytes from the bitset which may (not) contain a multiple of CHAR_BIT bits. I now how many of the bits in the bitset I need to put into an array. For example,
the bits set is declared as std::bitset < 40> id;
There is a separate variable nBits how many of the bits in id are usable. Now I want to extract those bits in multiples of CHAR_BIT. I also need to take care of cases where nBits % CHAR_BIT != 0. I am okay to put this into an array of uint8
bitset::to_ulong. As it is, I don't think there is a simple solution.std::bitsetdoesn't have something likedata()asstd::vectordoes (though the gcc version has an undocumented and experimental_M_getdatafunction which is just that...)`. Since there is no other thing, you can only access the individual bits separately. Or, serialize to a string or go via a stream, but neither of these is particularly efficient.