What is One-hot encoding?
State encoding that assigns one flip-flop per state with exactly one set at a time. Logic tends to be simple and fast, and it is common on FPGAs.
Japanese name: ワンホット符号化
State encoding that assigns one flip-flop per state with exactly one set at a time. Logic tends to be simple and fast, and it is common on FPGAs.
Japanese name: ワンホット符号化
In a finite state machine, one-hot encoding gives each state its own flip-flop, and exactly one flip-flop holds 1 at any time. Four states become 0001, 0010, 0100 and 1000. Testing whether the machine is in a given state means looking at a single bit, so outputs that depend on the state are often just one flip-flop or a small OR of a few. The next-state input of each flip-flop is the OR of the conditions on the transitions entering that state, each ANDed with the bit of the source state, which keeps the logic depth shallow and the machine fast.
Binary encoding numbers the states and needs only the ceiling of log2 N flip-flops: three states fit in two flip-flops, while one-hot needs three, and sixteen states need four flip-flops versus sixteen. The cost of binary encoding is wider decode logic, because recognizing a state means comparing all state bits. Gray-code encoding, a third option, assigns codes so that frequent transitions change one bit, reducing switching activity. Binary suits designs where flip-flops are scarce or the state count is large; one-hot suits speed and simplicity when flip-flops are plentiful.
An FPGA logic block pairs each small lookup table (LUT) with one or more flip-flops, so registers are abundant while wide logic functions must be split across several LUT levels. One-hot encoding fits this structure well: each state bit's next-state function usually involves only a few inputs and fits in a single LUT, which shortens critical paths. Synthesis tools commonly detect state machines and pick an encoding automatically, often one-hot for small and medium machines, though designers can override the choice. In ASICs, where flip-flops cost more area, binary or other compact encodings are more common.
With N flip-flops, one-hot uses only N of the 2^N possible patterns, so all-zero and multi-hot patterns are illegal. Noise, a glitch or a radiation-induced bit flip could put the machine into one of them, where it may stall or behave unpredictably. Binary encoding has the same issue with unused codes, such as 11 in a three-state machine. Robust designs therefore define a default branch that returns any unexpected state to a known one, and synthesis tools offer safe state-machine options that keep this recovery logic instead of optimizing it away.
Answer: C. It uses one flip-flop per state with exactly one set at a time, so next-state and output logic tend to be simple and fast
One-hot encoding represents, say, four states as 0001, 0010, 0100 and 1000, assigning one flip-flop to each state. It needs more flip-flops, but checking whether the machine is in a state means looking at a single bit, so next-state and output logic is shallow and tends to be fast. It is common on flip-flop-rich FPGAs, while binary encoding is used when flip-flop count must be minimized.
Answer: B. 2 / 3
Binary encoding numbers the states in binary, so three states fit in 2 bits (two flip-flops): 00, 01 and 10. One-hot encoding uses one flip-flop per state, so three. Binary leaves the unused code 11, so it is safer to define its destination with a default branch, letting the machine recover if noise ever puts it there. However, synthesis tools may optimize away the logic for recovering from unreachable states, so a tool setting that builds a safe state machine may also be needed.
One flip-flop per state, so a machine with N states needs N flip-flops. Binary encoding of the same machine needs only the ceiling of log2 N.
One-hot uses one flip-flop per state with a single bit set, giving simple, fast decode logic at the cost of more registers. Binary encoding stores the state number in the fewest flip-flops but needs wider logic to decode each state.
The idea is the same: a vector with exactly one element set to 1 identifies one item from a set. In hardware it encodes the current state of a state machine or a select signal, while in machine learning it represents a categorical value as a numeric vector.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.