The short answer

An encoder collapses many input lines into a short binary code. A decoder expands that code back into many output lines. TI’s SN74HC148 devices “encode eight data lines to 3-line (4-2-1) binary (octal)”, and its SN74HC138 reverses that. So the popular one-liner calls a decoder the inverse of an encoder. That answer breaks on the encoder’s own function table. Nothing asserted and input 0 asserted leave the same code on the output pins. Only the GS and EO status pins tell those two states apart. Both parts also run active-low, which changes how every table value reads.

Encoders and decoders sit on opposite sides of one idea. One turns an active line into a number, and the other reverses that. The symmetry is real, though it is not perfect.

This guide reads two Texas Instruments datasheets directly. The SN74HC148 priority encoder and the SN74HC138 decoder are both commodity parts you can still buy. Where the usual comparison tables disagree with those documents, the datasheet wins here.

Diagram showing an encoder collapsing eight active-low input lines into a three-bit code and a decoder expanding a three-bit code back into eight active-low output lines
An encoder narrows many lines into a code; a decoder widens a code back into many lines.

What Each One Converts

Start with the direction of the conversion, since everything else follows from it. An encoder has many inputs and few outputs. A decoder, conversely, has few inputs and many outputs.

TI states the encoder side plainly. Its SN74HC148 devices “encode eight data lines to 3-line (4-2-1) binary (octal)”. Eight data lines therefore shrink to three code pins.

The decoder side is a mirror of that. On the SN74HC138, “The three input pins, A, B, and C, select which output is active”. Three code pins expand back to eight lines.

Both parts are combinational circuits, so neither one stores anything. Texas Instruments says as much for the encoder, warning that “wrong addresses can appear during input transients”. Our combinational vs sequential circuit guide covers why that distinction matters.

Neither block is exotic, either. Encoders and decoders sit beside adders as basic combinational parts. Our half adder vs full adder guide covers that same family.

Inside a Real Encoder

The part to read is the SN54HC148 and SN74HC148 from Texas Instruments. Its datasheet, document SCLS109H, dates from April 2004, with a March 2022 revision. TI titles it “SNx4HC148 8-Line to 3-Line Priority Encoders”.

Read one sentence before you read any table, or every value will look wrong. TI writes that “Data inputs and outputs are active at the low logic level”. Active-low means a pin does its job when it sits low, rather than high.

A request therefore arrives on this encoder as a low, never as a high. An idle input line, meanwhile, stays high. The three code outputs also come out complemented.

Work one example through, because that complement trips people up. Pull input 7 low and the code pins A2, A1 and A0 all go low. Invert those three lows, so you get 111, which is decimal 7.

Input 0 gives the opposite pattern. Its code pins read high, high, high, which inverts to 000. That single fact sets up the trap in the next section.

The HC148 is not a plain encoder, though, and the word priority earns its place. TI describes “priority decoding of the inputs to ensure that only the highest-order data line is encoded”. Drive three inputs low at once and the highest-numbered one wins.

That ranking is a design decision rather than a detail. A plain encoder instead assumes exactly one active input at a time. Real inputs, such as interrupt lines or keypad rows, refuse to behave that way.

Two more pins handle expansion. Texas Instruments credits the “input enable (EI) and output enable (EO) signals” for that job. They allow “cascading multiple stages without added external circuitry”. The overview calls the result “octal expansion without the need for external circuitry”.

The Case a Plain Encoder Cannot Resolve

Diagram of three SN74HC148 function table rows that all output A2 A1 A0 as high, high, high, separated only by the GS and EO status pins
Three different states leave the same code on A2 A1 A0, so only GS and EO can tell them apart.

Here is the claim worth testing: a decoder is just an encoder run backwards. The HC148 function table, though, refutes it in two separate ways.

The first problem is collisions. A plain encoder is only defined when exactly one input is active. Two active inputs at once leave the output undefined, which is why the commodity part resolves them by rank.

The second problem survives even if only one input is active. Look at what the code pins do when nothing is asserted at all.

Remember that low means asserted on this part, because the table below is dense with H and L. Three of its rows produce the very same code, and only the status pins separate them.

EIData inputs 0 to 7A2 A1 A0GSEOWhat the row means
HAll eight ignoredH H HHHSwitched off, so the code means nothing
LAll eight highH H HHLSwitched on, though nothing is asserted
LInput 0 low, rest highH H HLHInput 0 is asserted, since GS reads low

Those three rows come from Table 8-1 of the SN74HC148 datasheet, with the eight data columns condensed into one. Every code pin therefore reads the same across all three. So the code alone cannot tell you what happened.

GS, however, answers the question the code pins cannot. That pin goes low when an enabled part actually has a request to report. Compare the last two rows and the difference jumps out.

Meanwhile, EO carries the other half of the story. It goes low only when EI sits low and every input stays idle. Chain it into the next stage’s EI and eight-line encoders cascade cleanly.

Still, none of this makes a plain encoder useless. It simply covers one case, the one-hot input. Real silicon then adds priority logic and status flags to cover everything else.

A decoder meets neither problem. Every input code is a legal code, so nothing needs arbitrating. Nothing is ambiguous either, because each of the eight codes owns its own output.

Inside a Real Decoder

The matching part is the SN54HC138 and SN74HC138. Its datasheet, document SCLS107G, goes back to December 1982, with an October 2021 revision. TI titles it “SNx4HC138 3-Line To 8-Line Decoders/Demultiplexers”.

Again, read the polarity note first, then read the table. TI says this device “features three binary inputs to select a single active-low output”. Therefore the active output is the one sitting low.

The overview spells the behaviour out in one line. “The selected output is pulled LOW, while the remaining outputs are all HIGH.” Seven idle pins read high, which looks backwards until you accept the polarity.

Selection itself is simple. “The three input pins, A, B, and C, select which output is active.” Three bits give eight codes, and the part uses all eight.

Three enable pins gate the whole thing. TI provides “Two active-low and one active-high enable inputs” on purpose. They “reduce the requirement for external gates or inverters when expanding”.

The payoff is concrete. “A 24-line decoder can be implemented without external inverters, and a 32-line decoder requires only one inverter.”

Now for a claim that needs a boundary drawn around it. Textbooks generally say a decoder activates exactly one output. For the HC138 that holds, and TI leans on it in an application note. The part “ensures that no more than one output is pulled to a low-level logic voltage”.

Two limits apply, though. Disable the part, and then no output is active at all. TI is explicit here, since “any enable pin can be deactivated to force all outputs high”. In fact, three of the eleven rows in its function table do exactly that.

The second limit is the bigger one. One-of-N decoders behave that way, while other decoders do not. TI’s CD74HC4511 is a BCD-to-seven-segment part, and its job is lighting several segments at once. Document SCHS279E calls the family “BCD-to-7 segment latch/decoder/drivers”.

Its function table settles the point. Feed the code for the digit 8, and all seven outputs drive high together. The code for 0 drives six outputs high, while output g stays low. That is a decoder lighting many outputs at once, by design.

So state the rule with its scope attached. A one-of-N decoder activates exactly one output while its enables all hold. A display decoder maps each code to a pattern instead.

Encoder vs Decoder: Comparison Table

Infographic comparing encoders and decoders on direction of conversion, input and output counts, behaviour on several active inputs, status pins, active level and typical applications
Encoder vs decoder at a glance: which way the conversion runs, how many lines are active, and what the real parts do.

The table below sets the two blocks against each other, row by row. Every value traces back to the TI datasheets named above.

AspectEncoder (SN74HC148)Decoder (SN74HC138)
Direction of conversionMany active lines down to a binary codeA binary code back out to many lines instead
Inputs on the real partEight data lines, plus the EI enableThree select pins as well as three enables
Outputs on the real partThree code pins, though GS and EO join themEight output lines
What the inputs meanWhich line is asking for serviceWhich line to select, because the code names it
What the outputs meanThe number of the asking lineWhich single line is active, while the rest idle
Inputs normally active at onceOne, since the plain form assumes one-hotAll three select pins, since a code needs every bit
Outputs normally active at onceOne code, though it can be ambiguousExactly one, while the enables hold
On several active inputsUndefined, unless the part ranks themCannot arise, since three pins only ever carry one code
How the real part settles that“priority decoding of the inputs”, so rank winsNothing to settle, since every code is legal
Status outputsGS and EO, because three rows share one codeNone, since no code is ambiguous
Enable pinsEI going in, EO coming out“Two active-low and one active-high enable inputs”
Expansion approach“octal expansion without the need for external circuitry”“A 24-line decoder can be implemented without external inverters”
TI’s own title“8-Line to 3-Line Priority Encoders”“3-Line To 8-Line Decoders/Demultiplexers”
Datasheet documentSCLS109H, revised March 2022SCLS107G, revised October 2021
Active level in silicon“Data inputs and outputs are active at the low logic level”“a single active-low output”
Reading the codeComplemented, so invert before readingStraight off the select pins instead
Demultiplexer roleNone, since TI ships it purely as an encoderThe same die, since TI calls them “3-to-8 decoders and demultiplexers”
Typical propagation delay“Typical tpd = 16ns”“Typical tpd = 15 ns”
Applications TI lists“N-Bit encoding”, “Code converters and generators”“LED Displays”, “Servers”, “Factory Automation”
Where it sits in a systemAhead of a narrow bus, ranking requests“high-performance memory-decoding or data-routing”
Combinational or sequentialCombinational, because nothing is storedCombinational too, since it stores nothing

One row carries most of the argument: the row for several active inputs. An encoder needs a rule there, whereas a decoder needs nothing. That asymmetry is why the inverse story breaks.

Decoder or Demultiplexer

Ask whether a decoder and a demultiplexer are the same thing and you get two confident, opposite answers. The datasheet gives a better one.

Start with the title on the front page: “SNx4HC138 3-Line To 8-Line Decoders/Demultiplexers”. TI describes the parts as “3-to-8 decoders and demultiplexers”. One piece of silicon, then, carries both names.

The difference lives in how you use the pins. TI is direct about it: “An enable input can be used as a data input for demultiplexing applications.” Hold the enables steady and the part decodes. Feed data into an enable, though, and the same part routes it.

In short, the roles differ, while the hardware does not. A decoder answers which line, whereas a demultiplexer answers which line gets this data. Our multiplexer vs demultiplexer guide covers the routing side in detail.

Two careless answers are worth avoiding here. Calling the pair identical ignores the enable pin’s second job. Saying they are unrelated ignores TI’s own product title.

Why the Real Parts Are Active-Low

Textbook diagrams almost always draw encoders and decoders active-high. A one on an input means asserted, and a one on an output means selected. Real parts, however, often invert both conventions.

Both chips here do exactly that. The HC148 datasheet says “Data inputs and outputs are active at the low logic level”. Likewise, the HC138 datasheet promises “a single active-low output”.

As a result, a student who reads a textbook and then a datasheet meets two different tables. Neither table is wrong. They simply use opposite polarity conventions.

Translating between them takes one habit. Read the pin label first, then decide what low means there. On the HC148, a low input is a request, while a low output bit is a one.

Active-low outputs are not an accident, either. For example, TI’s application section uses the HC138 as “a scanning column selector for an LED Matrix display”. The part supplies “the low side drive of the LED string”, so a low output is the useful one.

One caution belongs here. TI marks that application section as material that “is not part of the TI component specification”. Function tables carry the guarantees, whereas application text carries the ideas.

Where Each One Actually Shows Up

TI lists applications for both parts, and the two lists barely overlap. Start with the encoder.

The HC148 datasheet names “N-Bit encoding” plus “Code converters and generators”. Both jobs share one shape. Many lines arrive, and a short number leaves.

Priority is what makes that shape usable. Several devices can raise a request line simultaneously. The encoder then ranks them, and the highest-numbered request wins.

The HC138 list runs longer and more concrete. Texas Instruments names “LED Displays”, “Servers”, “Power Infrastructure” and “Factory Automation” among others. Its description targets “high-performance memory-decoding or data-routing applications”.

Memory decoding is the classic case. Three address bits pick one of eight chips, so only the selected chip answers. Instruction decoding inside a CPU follows a similar shape, as our hardwired vs micro-programmed control guide explains.

Neither part remembers anything between codes. Add a register and the behaviour changes completely, which is the sequential world our latch vs flip-flops guide covers. Decoders and encoders stay purely combinational.

Which One You Need

The choice is rarely a judgement call, because the wiring decides it. Count the lines on each side.

Many signal lines feeding a narrow bus call for an encoder. Keypad rows, interrupt requests and sensor flags all fit that shape. Add priority when two of them can fire together.

A narrow code feeding many targets calls for a decoder. Address lines picking one memory chip fit that shape exactly. Use the enable pins when you need every output parked.

Finally, one more question settles the demultiplexer case. Ask whether you are routing data or merely selecting a line. Routing data means feeding an enable pin, so the same HC138 does the work.

Interview Questions

An encoder turns an asserted line into a binary code. A decoder reverses that, since it turns a code back into one line. So the encoder narrows, whereas the decoder widens.

Not quite. A plain encoder is undefined when two inputs are active. Its code also cannot separate an idle part from input 0. TI’s SN74HC148 adds priority logic plus the GS and EO status pins for exactly those cases.

Because real input lines fire together. TI therefore describes “priority decoding of the inputs to ensure that only the highest-order data line is encoded”.

The same silicon, though not the same role. TI titles the SN74HC138 as decoders as well as demultiplexers. Its overview explains why, because “An enable input can be used as a data input for demultiplexing applications”.

Only a one-of-N decoder does, and only while its enables all hold. A BCD-to-seven-segment part such as TI’s CD74HC4511 drives several outputs together, because one digit needs several segments.

Frequently Asked Questions

An encoder converts many input lines into a shorter binary code. A decoder then converts that code back into many output lines. TI’s SN74HC148 encodes eight data lines into three, while its SN74HC138 turns three select pins into eight outputs.

Not exactly, since a plain encoder is only defined when one input is active. Its function table also gives the same code for an idle part and for input 0. The GS and EO status pins exist to separate those two states.

A priority encoder settles several active inputs by rank. TI’s SN74HC148 uses “priority decoding of the inputs to ensure that only the highest-order data line is encoded”. A plain encoder leaves that case undefined instead.

Both TI parts here work that way. The SN74HC148 datasheet says “Data inputs and outputs are active at the low logic level”. Similarly, the SN74HC138 selects “a single active-low output”. Textbook diagrams usually draw the opposite polarity, though, which is where the confusion starts.

One part serves both roles. TI titles the SN74HC138 as decoders as well as demultiplexers. It also notes that “An enable input can be used as a data input for demultiplexing applications”. Either hold the enables steady for decoding, or drive data into one for demultiplexing.

Only a one-of-N decoder does, and only while every enable is satisfied. TI notes that “any enable pin can be deactivated to force all outputs high”. A BCD-to-seven-segment decoder such as the CD74HC4511 lights several outputs for one code.

Both parts cascade through their enable pins. The SN74HC148 offers “octal expansion without the need for external circuitry” through EI and EO. The decoder side reaches further, since “A 24-line decoder can be implemented without external inverters”.

Both are combinational, so neither one stores state between codes. TI warns that the SN74HC148 is combinational logic, where “wrong addresses can appear during input transients”. Adding storage means adding latches or flip-flops around the part.

Wrapping Up

The two blocks answer opposite questions. An encoder asks which line is asking, while a decoder asks which line to pick. Reading them as exact inverses is where the trouble begins.

Keep three facts from the datasheets. Real parts run active-low. A plain encoder also needs status pins to stay unambiguous.

One HC138 die then serves as a demultiplexer too. Those three points answer nearly every exam question on this topic.

Related reading on DiffStudy:

Whatsapp-color Created with Sketch.

By Arun Kumar

Full Stack Developer with a BE in Computer Science, working with React, Next.js, Node.js, MongoDB, and AI/ML tools. Founder of DiffStudy — built to help CS students ace GATE and university exams, and keep developers up to date across AI, cloud, system design, web development, and every field of computer science. Every article is written from real hands-on experience, not just theory.

Leave a Reply

Your email address will not be published. Required fields are marked *


You cannot copy content of this page