title: Fastest way to scan for bit pattern in a stream of bits
body: <p>I need to scan for a 16 bit word in a bit stream. <em>It is not guaranteed to be aligned on byte or word boundaries</em>.  </p>
  
  <p>What is the fastest way of achieving this? There are various brute force methods; using tables and/or shifts but are there any "bit twiddling shortcuts" that can cut down the number of calculations by giving yes/no/maybe contains the flag results for each byte or word as it arrives?</p>
  
  <p>C code, intrinsics, x86 machine code would all be interesting.</p>