One-Hot State Encoding

A one-hot representation identifies one state by setting exactly one of a fixed number of bits.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Assign three states
  2. Check a transition
  3. Test whether exactly one state position is asserted
  4. Check transitions and recovery separately

Assign three states

Use 001 for idle, 010 for reading, and 100 for writing. The pattern 011 does not describe a valid single state under this encoding. Population count can test whether exactly one bit is set.

Check a transition

Changing from idle to writing replaces the state pattern with 100. Only setting the new bit would leave two bits active. A state transition table specifies all legal changes and what to do with invalid input.[1]

Test whether exactly one state position is asserted

In a four-state controller, code 0100 can represent state two when numbering starts at the right. Code 0110 asserts both state two and state one. Code 0000 asserts none and needs a deliberate reset or invalid-state policy. See population count.

State 0 → 0001
State 1 → 0010
State 2 → 0100
State 3 → 1000
Valid one-hot check: population count equals 1

Check transitions and recovery separately

A one-hot representation can simplify some decoding, while reserving many illegal patterns. Ensure a transition clears the old asserted position as it sets the new one. Test reset and the defined behavior if the internal state is invalid.

References

  1. Python Software Foundation, Python Standard Library: Built-in Types ↩