Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksToolsOpen the lab →

8-to-3 encoder (octal to binary): truth table and circuit

An 8-to-3 encoder turns one active input out of eight, D0 to D7, into its 3-bit binary number Y2 Y1 Y0. Each output is an OR of the four inputs whose number has that bit set: Y0 = D1 + D3 + D5 + D7, Y1 = D2 + D3 + D6 + D7, Y2 = D4 + D5 + D6 + D7.

It is also called an octal to binary encoder, and it does the reverse of a 3-to-8 decoder. D0 is not wired to anything: input 0 encodes as 000, which is also what the outputs show when no input is on, so practical encoders add a valid output V, the OR of all eight inputs, to tell the two apart. A plain encoder also assumes that exactly one input is active. Turn on D3 and D5 together and it outputs 111, a 7 that nobody pressed, because each output just ORs the codes of the active inputs. A priority encoder fixes that by letting the highest active input win. All 256 input combinations are checked against the OR equations before the page is built.

Live circuit: click the inputs to toggle them and watch the outputs update. It runs the real simulator, right here on the page.

Open this circuit in the lab →

What you need

Step by step

  1. Place inputs D7 to D0 and probes Y2, Y1 and Y0.
  2. Y0: OR together D1, D3, D5 and D7, the odd-numbered inputs.
  3. Y1: OR together D2, D3, D6 and D7.
  4. Y2: OR together D4, D5, D6 and D7, the upper half.
  5. Turn on one input at a time: the outputs spell its number in binary. D0 needs no gate at all.

8-to-3 encoder truth table

Active inputY2Y1Y0
D0000
D1001
D2010
D3011
D4100
D5101
D6110
D7111

The table assumes exactly one input is 1. With more than one, each output is the OR of their codes (D3 and D5 give 011 OR 101 = 111), which is why an encoder that reads real buttons is usually a priority encoder.

You can also read the full theory in the lesson on encoders and demultiplexers. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.

Build more parts from gates

Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.

Open the 8-to-3 encoder in the lab →

Frequently asked

What is an 8 to 3 encoder?

A combinational circuit with 8 inputs and 3 outputs that outputs the binary number of its one active input. It is also called an octal to binary encoder.

How many gates does an 8-to-3 encoder need?

Three 4-input OR gates, one per output bit, or nine 2-input ORs. Input D0 is not connected, because its code is 000.

What is the difference between an encoder and a decoder?

A decoder turns an n-bit number into one active line out of 2^n. An encoder does the reverse: it turns one active line back into its number.

What is the difference between an encoder and a priority encoder?

A plain encoder assumes exactly one input is active and gives a wrong code when two are. A priority encoder outputs the number of the highest active input and adds a valid output for when none is active.