title: Best way to generate CRC8/16 when input is odd number of BITS (not byte)? C or Python
body: <p>So I'm stuck with a protocol that adds a CRC8/CRC16 over odd number of bits.  (ie. it's not divisible by 8)  What's the best method to generate the CRC for it in software?</p>
  
  <p>There are plenty of CRC algorithm that uses table, but they are lookup per byte.  Of course, there's the "fail-safe" of doing it one bit at a time.  But is there a better approach?  Perhaps doing it mostly by table lookup and then finish it doing a bit at a time?</p>
  
  <p>I'm currently using a bitarray in python to handle this.  But solution in C would also work.  Thanks!</p>
  
  <p>EDIT:  Note that I'm interfacing with existing hardware that calc the CRC over the odd number of bits.  (It's easy for the HW, since they just use a LFSR--1 bit at a time!)  So while padding with known pattern would work for sake of integrity checking, it would break the hw compatibility.</p>