title: C/C++ Code to treat a character array as a bitstream
body: <p>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.</p>
  
  <p>I <em>could</em> 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.</p>
  
  <p>What I need is something like:</p>
  
  <pre><code>int get_bits(char* data, unsigned bitOffset, unsigned numBits);
  </code></pre>
  
  <p>so I could get the 7th 6-bit character in the data by calling:</p>
  
  <pre><code>const unsigned BITSIZE = 6;
  char ch = static_cast&lt;char&gt;(get_bits(data, 7 * BITSIZE, BITSIZE));
  </code></pre>