HDL & Verification

For a state machine with three states, how many flip-flops are needed to store the state (binary encoding / one-hot encoding)?

  1. A3 / 2
  2. B2 / 3
  3. C1 / 3
Show answer and explanation

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.

  • A. It is the other way around.
  • B. Correct. Two bits can represent up to four states.
  • C. One bit can represent only two states.
Practice this topic Back to topic

More HDL & Verification questions

  1. In the 4-bit counter above, when count is 15 and a rising clock edge arrives, what does count become?
  2. In Verilog, two 8-bit signals a and b are added and assigned to an 8-bit signal s (assign s = a + b;). What should be watched for?
  3. Intending a to be signed -1, someone wrote the code above, and gt became 1. Why?
  4. Which set of values makes up the four-state logic used in Verilog simulation?
  5. In simulation, a register without reset starts as X. What happens in the real chip?