title: Append 1 to 32 bit numbers to a char buffer
body: <p>I have a <code>char*</code> buffer, that I want to append integers of various bit sizes (between <code>1</code> and <code>32</code>) to.</p>
  
  <p>Thus, I need a function:</p>
  
  <pre><code>void addBits(char *buffer, int bits_appended_so_far, int object, int object_bit_size);
  </code></pre>
  
  <p>that can move an object of, say, <code>13</code> bits to the <code>470</code>th bit position of buffer.</p>
  
  <p>I could of course shift the bits onto the buffer one by one, but speed is of the essence so it seems like it should be possible to move larger chunks at a time. Is there a standard method to do this? Seems like there should be a standard method, but some googling and SO searching has not given me what I want.</p>