Before an FSM can be built, each state needs a code: a pattern of bits to store in the state flip-flops. That choice is the state encoding (or state assignment).
The main options:
- Binary encoding: number the states 0, 1, 2, … in binary. Uses the fewest flip-flops, ⌈log₂ N⌉ (see flip flops needed).
- One-hot encoding: one flip-flop per state, exactly one of them 1. More flip-flops, but the next-state logic is very simple.
- Gray encoding: neighboring states in a sequence differ in one bit, which can simplify logic and reduce switching.
The codes you choose change the next-state equations and output equations, sometimes a lot. Codes left over with binary encoding are unused states: they can be don't-cares in the logic, but you must check they can't cause a lock up state.
A useful habit: when the states have meanings that map onto bits ("last input was 1"), use those bits as the code. The equations often fall straight out.