Interview Question · Code Writing
Logic Gates from a 2:1 Mux
- Asked at Micron
- Asked at Infineon
- Asked at Texas Instruments
The Question
The interviewer asks
You have only 2:1 multiplexers and the constants 0 and 1. Build NOT, AND, OR and XOR.
You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
Write the mux as y = s ? b : a and put one input on the select. NOT a is a ? 0 : 1. AND is a ? b : 0, and OR is a ? 1 : b. XOR is a ? ~b : b, so it needs a second mux to make ~b. Five muxes cover all four gates.
y = s ? d1 : d0. Arrows carry signals; the label names the mux input.- Make ~b
With
bon the select and constants 1 and 0 on the data inputs, mux 1 is an inverter. - Pick b or ~b
When
ais 0, mux 2 passesb. Whenais 1, it passes~b. That is XOR.
Read the diagram as text
- a: input
- b: input
- Mux 1: NOT: b ? 0 : 1 gives ~b
- Mux 2: XOR: a ? ~b : b
- y: a XOR b
- b → Mux 1: NOT: s
- Mux 1: NOT → Mux 2: XOR: d1 = ~b
- b → Mux 2: XOR: d0 = b
- a → Mux 2: XOR: s
- Mux 2: XOR → y
NOT, AND and OR take one mux each. XOR takes two, so five muxes cover all four gates.
| Gate | Select | When select is 0 | When select is 1 |
|---|---|---|---|
| NOT a | a | 1 | 0 |
| a AND b | a | 0 | b |
| a OR b | a | b | 1 |
| a XOR b | a | b | ~b (one more mux) |
All four input rows, checked against the operators. The synthesizer reduces the five muxes to four plain gates.
a=0 b=0 not=1 and=0 or=0 xor=0 a=1 b=1 not=0 and=1 or=1 xor=0 PASS: five 2:1 muxes give NOT, AND, OR and XORSelf-Check
Tick each key point you covered in your answer.
What Interviewers Listen For (Fresher)
A good fresher answer writes the mux equation first, then fills each data input from a truth table. It checks each gate against all four rows.
What Interviewers Listen For (Junior)
A good junior answer notices that XOR needs ~b and builds it with a second mux. It says the synthesizer sees only the function and maps it to its own cells.
Cross-Questions
Where the interviewer goes next. Open a node to practise that follow-up.
WhyWhat IfProve ItCompare
- Logic Gates from a 2:1 Mux
-
What IfA 2:1 Mux from NAND GatesL0 Fresher
What if you have only NAND gates? Build a 2:1 mux.
2:30You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
Four NANDs are enough. One NAND with its inputs tied makes
~s. Two NANDs gateawith~sandbwiths. A last NAND combines them, because NAND of two NANDs is an OR of two ANDs.RUNIcarus Verilog · in your browserExpected:4 NAND gates, 8 input rows, 0 wrongPASS: four NANDs make a 2:1 muxSelf-Check
Tick each key point you covered in your answer.
Half-Truth
Uses five gates because "an inverter is a separate cell".
A NAND with both inputs tied is an inverter, so the count stays at four NANDs.
-
CompareA 4:1 Mux as a Look-Up TableL0 FresherL1 Junior
Compare building gates from 2:1 muxes with using one 4:1 mux. How can a 4:1 mux make any 2-input function?
2:30You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
Drive the two inputs onto the select and tie the four data inputs to the truth table. The select then picks the output row directly. Changing the four constants changes the function, with no new wiring. This is how an FPGA look-up table works.
RUNIcarus Verilog · in your browserExpected:a=0 b=0 nand=1 xnor=1a=1 b=1 nand=0 xnor=1PASS: the same 4:1 mux made NAND and XNOR from two truth tablesSelf-Check
Tick each key point you covered in your answer.
Missed Corner
Puts the truth table in the wrong bit order and blames the mux.
Bit
{a, b}of the table is the output for that row. Writing the rows from 00 upward reverses the table.Source Measured: the run on design.puzzle.mux-as-lut, Icarus Verilog 12
-
WhyWhy a 2:1 Mux Is a Universal GateL0 FresherL1 Junior
Why can a 2:1 mux build any logic function?
2:30You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
With constants it makes NOT and AND, and NOT plus AND can express every Boolean function. A mux also splits a function on one variable:
f = x ? f(x=1) : f(x=0). Repeat the split on each variable and you get a tree of muxes for any truth table.Self-Check
Tick each key point you covered in your answer.
Half-Truth
"Only NAND and NOR are universal."
Any set that can make NOT and AND (or NOT and OR) is complete. A mux with constant inputs makes both.
-
Prove ItSolve R1.1.1: A Four-Input MuxSimulator-graded
Show it, don't just say it: this Silicon Lab problem is graded by the simulator.
What People Get Wrong
Common wrong answers and why they fail. Run It shows the wrong belief failing on a real simulator.
Misconception
Writes AND as a ? 0 : b.
The input on the 0 side is chosen when a is 0. This mapping gives ~a & b, and the twin finds it wrong in two of four rows.
Run It
The AND mux with its data inputs swapped.
FAIL: a ? 0 : b is not AND; it gives ~a & b, wrong in 2 of 4 rowsSee the Fix
// mux2: y = s ? b : a
module mux2 (input logic s, a, b, output logic y);
assign y = s ? b : a;
endmodule
module gates (input logic a, b, output logic y_not, y_and, y_or, y_xor);
logic nb;
mux2 m_not (.s(a), .a(1'b1), .b(1'b0), .y(y_not)); // a ? 0 : 1
mux2 m_and (.s(a), .a(1'b0), .b(b), .y(y_and)); // a ? b : 0
mux2 m_or (.s(a), .a(b), .b(1'b1), .y(y_or)); // a ? 1 : b
mux2 m_nb (.s(b), .a(1'b1), .b(1'b0), .y(nb)); // nb = ~b
mux2 m_xor (.s(a), .a(b), .b(nb), .y(y_xor)); // a ? ~b : b
endmodule
module tb;
logic a, b, y_not, y_and, y_or, y_xor;
int bad = 0;
gates g (.*);
initial begin
for (int i = 0; i < 4; i++) begin
{a, b} = i[1:0]; #1;
$display("a=%b b=%b not=%b and=%b or=%b xor=%b", a, b, y_not, y_and, y_or, y_xor);
if (y_not !== ~a || y_and !== (a & b) || y_or !== (a | b) || y_xor !== (a ^ b)) bad++;
end
if (bad == 0) $display("PASS: five 2:1 muxes give NOT, AND, OR and XOR");
end
endmodule
Prints: PASS: five 2:1 muxes give NOT, AND, OR and XOR
Half-Truth
Claims XOR fits in one mux with only a, b, 0 and 1.
With a on the select, the two data inputs must be b and ~b. Without an inverted b signal, one mux cannot do it.
Delivery
Answers without stating which mux input is selected by 0.
Every answer depends on that convention. An interviewer expects it said first, so the mapping can be checked.