I have a big lump of binary data in a char[] array which I need to interpret as an array of packed 6-bit values.
I could sit down and write some code to do this but I’m thinking there has to be a good extant class or function somebody has written already.
What I need is something like:
int get_bits(char* data, unsigned bitOffset, unsigned numBits);
so I could get the 7th 6-bit character in the data by calling:
const unsigned BITSIZE = 6; char ch = static_cast<char>(get_bits(data, 7 * BITSIZE, BITSIZE));
This may not work for sizes greater than 8, depending on endian system. It’s basically what Marco posted, though I’m not entirely sure why he’d gather one bit at a time.