One-hot encoding represents one of states using bits, with exactly one bit set (“hot”) and the rest zero. State is with the at position .
This is wasteful in bit count compared to binary (which packs states into bits) but it has practical advantages.
Where it’s used
- Decoder outputs. A 3-to-8 decoder produces a one-hot 8-bit output: input → .
- Finite state machine encoding. Assign each FSM state to its own bit. Transitioning between states is just clearing one bit and setting another — no decoding needed before checking “are we in state X?”
- Address decoding. Memory chip-select lines are one-hot — exactly one chip is selected at a time.
- Multiplexer select. Some MUX designs use one-hot select lines (one wire per data input) instead of binary select.
Why it’s faster (sometimes)
To check “is state == 5?” with binary encoding, you need a 3-input AND of select lines (with appropriate inversions). With one-hot, you just check whether the bit for state 5 is set — a single wire. No combinational logic required.
The trade-off is wires and flip-flops. A one-hot FSM with states uses flip-flops; a binary-encoded FSM uses . For small FSMs ( states) the wire count usually wins on speed, especially in FPGAs where flip-flops are cheap and routing is the bottleneck.
Binary ↔ one-hot
A Decoder converts binary to one-hot: 2 input bits → 4 output lines.
An Encoder (or priority encoder) does the reverse: 4 input lines → 2 binary output bits.
Other encoding choices
Several variants of “compact representation of one of states”:
- Binary: bits, fully packed. Compact but needs decoding logic.
- One-hot: bits, exactly one set. Decode-free but uses flip-flops.
- One-cold: bits, exactly one cleared. Same trade-offs as one-hot but with inverted polarity. Used in some legacy systems where the inactive (idle) state should be all-1s.
- Gray code: bits, but adjacent states differ in only one bit. Used in K-maps and to reduce switching activity in FSMs. Same density as binary but with the adjacency property.
- Johnson code (twisted-ring counter): bits cycling through states, transitioning by shifting and inverting one end. Another decode-friendly compact code.
Each has its niche. One-hot dominates for small FSMs in FPGAs because of the speed-and-simplicity advantage.
One-hot in machine learning
The same idea is heavily used in machine learning, where it’s called one-hot encoding of categorical variables. To encode “color = red” out of {red, green, blue}, use the vector . ML models can then process the categorical variable as a numeric input.
The downside is the same as in hardware: dimensionality. A categorical with 1000 categories needs 1000 features. Modern alternatives (embeddings, hashing tricks) compress this back down for high-cardinality categoricals.
When to choose one-hot
The classic use case in digital design: FSM state encoding for FPGAs.
For an FSM with 8 states:
- Binary: 3 flip-flops, LUTs of decoding logic to identify states.
- One-hot: 8 flip-flops, 0 LUTs of decoding (just check the right bit).
In an FPGA, each LUT is roughly the same area as one flip-flop, so the trade is comparable. [Note: this specific claim is from general knowledge and hasn’t been independently verified.] But the one-hot is faster — no decoding delay before state checks. For small-to-medium FSMs in FPGAs, one-hot wins.
For very large FSMs (50+ states), binary’s compactness eventually wins. Synthesis tools often choose automatically based on the state count.
For the reverse direction, see Encoder. For other compact encodings (Gray code), see Counter (digital) which uses similar principles.