dimanche 25 décembre 2016

convert vector of uint8_t to bitset

In the following code I've a uint8_t vector filled from some binary file which contains information in some_size number of bytes -

std::ifstream db(path.c_str(), std::ios::binary);
std::vector <uint8_t> buffer(some_size, 0);
db.read(reinterpret_cast<char *>(&buffer.front()), some_size);
db.close();

Now I know from some index say 20, there exists 37 bytes of either 1 or 0 which I need to fill into a bitset. The bitset looks like std::bitset<37> booleans; and is initialized to all 0s initially. Now if initial index is 20, so I need to fill booleans with 37 boolean values that are present in bytes which will range from buffer[20] to buffer[57]. Apart from looping over the vector, is there any other way to convert those bytes to this bitset?

Aucun commentaire:

Enregistrer un commentaire