title: Reading variable length bits from a binary string
body: <p>Im new to javascript and node.js, I have a base64 encoded string of data that I need to parse several values from which are of various bit lengths.</p>
  
  <p>I figured I would start by using the Buffer object to read the b64 string but from there I am completely lost.</p>
  
  <p>The data are a series of unsigned integers, The format is something akin to this:
  Header:  </p>
  
  <pre><code>8 bits - uint  
  3 bits - uint  
  2 bits - uint  
  3 bits - unused padding  
  6 bits - uint
  </code></pre>
  
  <p>After that there are recurring sections of either 23 bit or 13 bit length of data each with a couple of fields I need to extract.</p>
  
  <p>An example of a 23 bit section:  </p>
  
  <pre><code>3 bit - uint  
  10 bit - uint  
  10 bit - uint  
  </code></pre>
  
  <p>My question is this, What is the best way to take an arbitrary number of bits and put the resulting value in a separate uint? Note that some of the values are multi-byte (> 8 bits) so I cant step byte for byte.</p>
  
  <p>I apologize if my explanation is kind of vague but hopefully it will suffice.</p>