Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C/C++ Code to treat a character array as a bitstream

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));
like image 798
AndrewR Avatar asked Nov 05 '08 07:11

AndrewR


1 Answers

Boost.DynamicBitset - try it.

like image 165
Igor Semenov Avatar answered Nov 09 '22 13:11

Igor Semenov