Я думаю, что-то в строке следующего может работать.
int get_bit(char *data, unsigned bitoffset) // returns the n-th bit
{
int c = (int)(data[bitoffset >> 3]); // X>>3 is X/8
int bitmask = 1 << (bitoffset & 7); // X&7 is X%8
return ((c & bitmask)!=0) ? 1 : 0;
}
int get_bits(char* data, unsigned bitOffset, unsigned numBits)
{
int bits = 0;
for (int currentbit = bitOffset; currentbit < bitOffset + numBits; currentbit++)
{
bits = bits << 1;
bits = bits | get_bit(data, currentbit);
}
return bits;
}
Я не отлаживал и не проверял его, но вы можете использовать его в качестве отправной точки.
Кроме того, учитывайте порядок следования битов. Вы можете изменить
int bitmask = 1 << (bitoffset & 7); // X&7 is X%8
до
int bitmask = 1 << (7 - (bitoffset & 7)); // X&7 is X%8
в зависимости от того, как был сгенерирован битовый массив.