Skip to content
BetterDL

One-hot

Also called: one-hot code, one-hot encoding, one hot, 1-hot

A group of bits in which exactly one bit is 1 and all the others are 0, so the position of the 1 identifies the value.

A pattern is one-hot when exactly one of its bits is 1. The value isn't read as a binary number; it's read from where the 1 sits.

With four lines, the one-hot patterns are 0001, 0010, 0100 and 1000. Each means "line 0", "line 1", "line 2" or "line 3".

You meet one-hot signals all over digital design:

  • The outputs of a decoder (without enable, or with it on) are always one-hot.
  • A plain encoder assumes its inputs are one-hot; with two lines active it gives nonsense.
  • Memory word lines and chip selects are one-hot, so only one row or chip responds.
  • In a state machine, one-hot state encoding gives each state its own flip-flop.

The trade-off against binary:

  • Binary packs N values into ⌈log₂N⌉ bits. One-hot needs N bits.
  • One-hot needs no decoding: checking "are we in value 3?" is just reading one wire.

All zeros is not one-hot (no line active), and neither is any pattern with two or more 1s. The mirror idea, exactly one bit 0, is sometimes called one-cold, and it's what decoders with active low outputs produce.

0
128
0
64
1
32
0
16
0
8
0
4
0
2
0
1

Worked examples

Example

Decoder output as a one-hot word

A 3-to-8 decoder receives A B C = 101 (A is the MSB). Write Y7…Y0 as one word.

  1. 1.

    101₂ = 5, so only Y5 is 1.

  2. 2.

    Y7…Y0 = 00100000: the 1 is in position 5, counting from 0 on the right.

  3. 3.

    Read as a binary number, 00100000 is 32. That's not the value; the position, 5, is.

Example

Checking for one-hot

Which of these 4-bit patterns are one-hot: 0100, 0000, 0110, 1000?

  1. 1.

    0100: one 1. One-hot (line 2).

  2. 2.

    0000: no 1s. Not one-hot.

  3. 3.

    0110: two 1s. Not one-hot.

  4. 4.

    1000: one 1. One-hot (line 3).

Common mistakes

  • Reading one-hot as a binary number. 0100 means line 2, not the value 4.

  • Counting all-zeros as one-hot. One-hot needs exactly one 1.

  • Expecting one-hot to save bits. It uses one bit per value, far more than binary for large counts.

Practice One-hot

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

One-hot is taught in Combinational Logic and Finite State Machines.