Lesson 13 of 15

Decoder

Decoder

A decoder converts a binary code into one-hot output — exactly one output line goes high for each input combination.

A 2-to-4 decoder has:

  • 2 input lines: A1, A0
  • 4 output lines: Y0, Y1, Y2, Y3
  • Exactly one Yi is 1 for each input
A1A0Y0Y1Y2Y3
001000
010100
100010
110001

The selected output Yi = 1 when the binary address equals i.

Decoders are used for memory address decoding (selecting which memory chip to activate), instruction decoding in CPUs, and driving 7-segment displays.

Your Task

Implement decoder2to4(a1, a0) that returns an array [Y0, Y1, Y2, Y3] where exactly one element is 1.

JavaScript loading...
Loading...
Click "Run" to execute your code.