Digital Logic
One-Hot Encoding
An encoding scheme where exactly one bit is high among a group, with each state represented by a single active bit position.
Detailed Explanation
In one-hot encoding, N states require N bits, with exactly one bit high at a time. State 0 is 0001, state 1 is 0010, state 2 is 0100, etc. This contrasts with binary encoding where N states need log2(N) bits.
One-hot uses more flip-flops but simplifies next-state and output logic—each state bit directly indicates that state. State transitions become simple bit clears and sets. Error detection is easy (check for exactly one bit high).
Code Example
systemverilog
// One-hot FSM
logic [3:0] state_q; // 4 states, one-hot
localparam IDLE = 4'b0001, RUN = 4'b0010,
WAIT = 4'b0100, DONE = 4'b1000;
always_ff @(posedge clk or posedge reset) begin
if (reset)
state_q <= IDLE;
else begin
state_q <= '0; // Clear all
case (1'b1)
state_q[0]: state_q <= start ? RUN : IDLE;
state_q[1]: state_q <= WAIT;
state_q[2]: state_q <= ready ? DONE : WAIT;
state_q[3]: state_q <= IDLE;
endcase
end
end