Search code examples
state-machine

How to encode finite state machine as a binary string?


How to encode / decode Finite state machines as a binary strings?

F: [0,1,00,01,...] -> [fsm1, fsm2,...], |fsm1|=<|fsm2|
Decode: Binary string -> FSM

Solution

  • To represent an FSM, state diagrams can be encoded in DOT format: https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29

    To implement an FSM in hardware, a Hardware Description Language is the appropriate tool: https://www.microsemi.com/document-portal/doc_view/130043-state-machine-an

    To implement an FSM in software, the machine can be captured with one or two look-up tables.

    One LUT would be sufficient for Mealy machines, where outputs are defined with state transitions: each (state, input) combination would index to a (state, output) tuple.

    Moore machines - where outputs are determined by state - would require a second look-up: the above table would yield only the state, with a second table mapping that state to its output.

    Once these tables are represented in your format of choice, say JSON, then serialization should be easy.