Skip to content
BetterDL

Binary state encoding

Also called: binary state assignment, binary-encoded states, minimal state encoding

A state encoding that numbers the states 0, 1, 2, … in binary, using the fewest possible flip-flops: ⌈log₂ N⌉ for N states.

Binary state encoding gives each state a binary number as its code. A 5-state machine could use S0 = 000, S1 = 001, S2 = 010, S3 = 011, S4 = 100.

Its big advantage is economy: it uses the minimum number of flip-flops, the smallest n with 2ⁿ ≥ N (see flip flops needed). For 5 states that's 3; for 100 states only 7, where one-hot would need 100.

The costs:

  • More logic. Every state is a pattern across several bits, so next-state and output logic usually involve all the state bits.
  • Unused codes. When N isn't a power of 2, 2ⁿ − N codes are unused. They help as don't-cares, but they must be checked for lock-up.
  • Order matters. Which state gets which number changes the equations. Giving neighboring states codes that differ in one bit (a gray code order) often helps.

Counters are the natural fit: a binary counter's states are binary numbers, so the encoding is free.

1
4
0
2
0
1

Worked example

Example

Encoding 5 states

A machine has states Idle, Wait, Run, Done and Error.

  1. 1.

    Smallest n with 2ⁿ ≥ 5: 2² = 4 is too few, 2³ = 8 is enough → 3 flip-flops.

  2. 2.

    Assign Idle = 000, Wait = 001, Run = 010, Done = 011, Error = 100 (the diagram shows Error's code).

  3. 3.

    Codes 101, 110 and 111 are unused: 8 − 5 = 3 don't-care rows in every next-state K-map.

Common mistakes

  • Rounding ⌈log₂ N⌉ down: 5 states need 3 flip-flops, not 2.

  • Assuming every binary assignment gives the same logic. Swapping codes can shrink or grow the equations.

Practice Binary state encoding

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Binary state encoding is taught in Finite State Machines.