State Encoding
State encoding is the choice of binary patterns assigned to a state machine's states, affecting logic size and speed.
Why it matters
A finite state machine stores its state as bits in a register. How the abstract states map to bit patterns is a design choice that changes the size of the next-state and output logic, the speed of the machine, and its power use.
Binary encoding
The most compact scheme numbers the states 0, 1, 2, and so on in binary. An FSM with N states needs only ceil(log2 N) flip-flops. This uses the fewest registers but the next-state logic can be complex, since each output bit may depend on all state bits.
One-hot encoding
One-hot uses one flip-flop per state, with exactly one bit high at a time. It needs many more registers but the logic is simple and fast: a state is decoded by testing a single bit. One-hot is favored in FPGAs, which have abundant flip-flops.
Gray encoding
Gray coding assigns patterns so that adjacent states differ by only one bit. This limits transient behavior during transitions and is useful where only neighboring transitions occur, such as counters that cross clock domains.
The trade
There is no single best encoding. Binary minimizes registers, one-hot minimizes logic depth, and Gray minimizes switching. The right choice depends on the target technology and the machine's structure.