Fastest way to scan for bit pattern in a stream of bits

后端 未结 13 1812
悲哀的现实
悲哀的现实 2020-12-07 13:38

I need to scan for a 16 bit word in a bit stream. It is not guaranteed to be aligned on byte or word boundaries.

What is the fastest way of achieving this

13条回答
  •  旧时难觅i
    2020-12-07 14:38

    I would implement a state machine with 16 states.

    Each state represents how many received bits conform to the pattern. If the next received bit conform to the next bit of the pattern, the machine steps to the next state. If this is not the case, the machine steps back to the first state (or to another state if the beginning of the pattern can be matched with a smaller number of received bits).

    When the machine reaches the last state, this indicates that the pattern has been identified in the bit stream.

提交回复
热议问题