Three short digital logic interview questions: a bitwise XOR, NAND and OR of two 4-bit numbers with the fewest gates, building a 5:1 function generator from 4:1 parts, and counting the 4:1 multiplexers needed for an 8:1 multiplexer. Here are the questions, followed by the answers and the reasoning an interviewer wants to hear.
The questions
1. Given two 4-bit numbers, A = 1001 and B = 1100:
- How do you XOR them using the minimum number of gates?
- How do you NAND them?
- How do you OR them?
2. Given a 4:1 function generator, how do you build a 5:1 function generator using only 4:1 function generators? What happens to the unused inputs?
3. Using 4:1 muxes, how many 4:1 muxes do you need to design an 8:1 mux?
Question 1 in plain words
A bitwise operation on two 4-bit numbers works on each bit position separately. Bit 0 of A only meets bit 0 of B, bit 1 only meets bit 1, and so on. Nothing carries from one position to the next, unlike addition. So the minimum hardware is one two-input gate per bit: four XOR gates for the XOR, four NAND gates for the NAND and four OR gates for the OR.
| Operation | A = 1001, B = 1100 | Gates |
|---|---|---|
| A XOR B | 0101 | 4 two-input XOR |
| A NAND B | 0111 | 4 two-input NAND |
| A OR B | 1101 | 4 two-input OR |
The trap is to overthink it. Interviewers ask this to see whether you recognize that the bits are independent. A good follow-up from them is "what if you only have NAND gates?", which is covered in the deep dive.
Question 2 in plain words
A 4:1 multiplexer (also called a function generator in this kind of question) picks one of four inputs using two select lines. To pick one of five inputs, you need three select lines, and you need a second stage. The first 4:1 mux chooses among inputs 0 to 3. A second 4:1 mux then chooses between the first mux's output and input 4. Two 4:1 muxes are enough.
The second mux uses only two of its four data inputs. The unused data inputs and the unused select line must be tied to a fixed logic level, normally ground. Leaving a CMOS input floating lets it drift to an undefined voltage, which can cause extra current and unpredictable outputs.
Question 3 in plain words
An 8:1 mux needs three 4:1 muxes. Two of them each handle four of the eight inputs, using the two low select bits. The third picks between those two outputs using the top select bit, with its other two data inputs tied off. If a 2:1 mux is allowed, you would use two 4:1 muxes and one 2:1 mux instead.
Deep dive: the numbers and details
This part holds the truth tables, the gate counts, a general formula and the follow-up questions. Skip it if the overview is all you need.
Bit-by-bit working for question 1
| Bit | A | B | XOR | NAND | OR |
|---|---|---|---|---|---|
| 3 | 1 | 1 | 0 | 0 | 1 |
| 2 | 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 | 1 | 1 |
Reading bit 3 down to bit 0 gives XOR = 0101, NAND = 0111 and OR = 1101.
If only NAND gates are allowed
NAND is universal, so every function can be built from it, but the gate count changes:
- NAND: 1 gate per bit, 4 in total.
- OR: a OR b = NAND(NOT a, NOT b), and each NOT is a NAND with its inputs tied together. That is 3 gates per bit, 12 in total.
- XOR: the classic 4-NAND circuit. Let n = NAND(a, b); then a XOR b = NAND(NAND(a, n), NAND(b, n)). That is 4 gates per bit, 16 in total, and three gate delays deep.
For bit 2 of the example (a = 0, b = 1): n = 1, NAND(0, 1) = 1, NAND(1, 1) = 0, and NAND(1, 0) = 1, which matches 0 XOR 1 = 1.
The 5:1 mux, select by select
Call the inputs I0 to I4 and the select bits s2 s1 s0, with valid codes 000 to 100.
- Mux A: data inputs I0, I1, I2, I3; selects s1 s0. Its output is the right answer whenever s2 = 0.
- Mux B: data input 0 = output of mux A, data input 1 = I4, data inputs 2 and 3 tied to ground; its low select = s2 and its high select tied to 0.
When s2 = 0, mux B passes mux A's output. When s2 = 1, it passes I4, whatever s1 and s0 are. That means the unused codes 101, 110 and 111 all select I4. A good answer says this out loud and states whether the design should treat those codes as "don't care" or flag them as errors.
The 5-input function reading of question 2
Some interviewers mean "function generator" in the FPGA sense: a look-up table (LUT) that can produce any function of its inputs. Then the question is how to build any 5-input function from 4-input LUTs. The answer is Shannon expansion on the fifth input x5:
f = (NOT x5 AND f0) OR (x5 AND f1), where f0 = f with x5 = 0 and f1 = f with x5 = 1.
Two 4-input LUTs compute f0 and f1 from the other four inputs. A 2:1 mux driven by x5 picks between them. If only 4-input LUTs are allowed, the 2:1 mux is a third LUT using three of its four inputs, with the fourth tied to a constant and ignored in its truth table. The original Xilinx Virtex CLB added a dedicated F5 multiplexer for exactly this job, as described in the Virtex data sheet (DS003).
A general formula for mux trees
Each 4:1 mux takes four signals and leaves one, so it reduces the number of candidates by 3. To go from N inputs down to 1 you need N - 1 reductions, so the number of 4:1 muxes is the ceiling of (N - 1) / 3.
| Target | 4:1 muxes | Levels |
|---|---|---|
| 5:1 | 2 | 2 |
| 8:1 | 3 | 2 |
| 16:1 | 5 | 2 |
| 64:1 | 21 | 3 |
The number of levels sets the delay: a 16:1 mux built as four first-level muxes plus one second-level mux has two mux delays from data input to output, and the select bits for the first level must be stable before the data path settles.
The 8:1 mux in Verilog
// 8:1 mux from three 4:1 muxes
module mux4 (input [3:0] d, input [1:0] s, output y);
assign y = d[s];
endmodule
module mux8 (input [7:0] d, input [2:0] s, output y);
wire lo, hi;
mux4 m0 (.d(d[3:0]), .s(s[1:0]), .y(lo));
mux4 m1 (.d(d[7:4]), .s(s[1:0]), .y(hi));
mux4 m2 (.d({1'b0, 1'b0, hi, lo}), .s({1'b0, s[2]}), .y(y));
endmodule
The third instance ties its two upper data inputs and its upper select bit to 0, which is the "unused inputs" point from question 2 written as code.
Follow-up questions to expect
- Build a 2:1 mux from NAND gates only (answer: 4 NAND gates, including one used as an inverter on the select).
- Can a mux implement any function? Yes: a 2n:1 mux with the function's truth table on its data inputs implements any n-input function, which is how a LUT works.
- Why tie unused inputs instead of leaving them open? Floating CMOS inputs can sit near the switching threshold, drawing current through both transistors and making the output unpredictable.
Further reading
- Can You Build a Mux Out of XOR Gates? Proof and Fix (this blog)
- Verilog Awareness: Interview Questions on Muxes, Assignments and Coding (this blog)
- Xilinx Virtex 2.5 V FPGA data sheet, DS003 v1.7, October 1999 (logic cells, LUTs and the F5 multiplexer)


Interview questions at cisco.
ReplyDelete1. In order to find out stack fault of a three input nand gate how many necessary input vectors are needed ?
2. What is parity generation ?
3. A nand gate becomes ___ gate when used with negative logic ?
4. What is the advantage of cmos over nmos ?
5. What is the advantage of synchronous circuits over asynchronous circuits ?
6. What is the function of ALE in 8085 ?
7. A voice signal sample is stored as one byte. Frequency range is 16 Hz to 20 Hz. What is the memory size required to store 4 minutes voice signal?
8. What will the controller do before interrupting CPU?
9. In a normalized floating point representation, mantissa is represented using 24 bits and exponent with 8 bits using signed representation. What is range ?
10. The stack uses which policy out of the following– LIFO, FIFO, Round Robin or none of these ?
11. Where will be the actual address of the subroutine is placed for vectored interrupts?
12. Give the equivalent Gray code representation of AC2H.
13.What is the memory space required if two unsigned 8 bit numbers are multiplied ?
14. The vector address of RST 7.5 in 8085 processor is _______.
15. Subtract the following hexadecimal numbers— 8416 - 2A16
16. Add the following BCD numbers— 1001 and 0100
17. How much time does a serial link of 64 Kbps take to transmit a picture with 540 pixels.
18. Give the output when the input of a D-flip flop is tied to the output through the XOR gate.
19. Simplify the expression AB + A( B + C ) + B ( B + C )
20. Determine the logic gate to implement the following terms–ABC, A+B+C
21. Implement the NOR gate as an inverter.
22. What is the effect of temperature on the Icb in a transistor
23. What is the bit storage capacity of a ROM with a 512*4 organization?
24. What is the reason of the refresh operation in dynamic RAM’s ?
25. Suppose that the D input of a flip flop changes from low to high in the middle of a clock pulse. Describe what happens if the flip flop is a positive edge triggered type?
26. How many flip flops are required to produce a divide by 32 device ?
27. An active HIGH input S-R latch has a 1 on the S input and a 0 on the R input. What state is the latch in?
28. Implement the logic equation Y = C^BA^ + CB^A + CBA with a multiplexer.
(where C^ stands for C complement)
29. Equivalent Gray code representation of AC2H.
30. What does a PLL consist of ?
Must Know Question
ReplyDelete1. Setup Time and Hold Time:
* What is it ?
* How do you solve the setup and hold time issues ?
* What are the factors that affect them ?
* Does changing the clock period affect setup/hold issues ? Why or why not ?
2. ASIC Design Flow/FPGA Design Flow:
* Flow from spec to gds
* Understand the Inputs/Outputs at each stage of the flow
* Question will be related to the projects/design you have done
3. Clock Related Stuff:
* Clock Skew
* Clock Trees
* Clock Latency
* Clock Insertion Delay
* Clock Period
* Clock Trees
* Max Clock Frequency
* Glitch ? What, Why and How to avoid it ?
* Useful Skew
* Effective Skew
* Clock Buffers ? How are they different from regular buffers ?
Synthesis Basic Questions
1. Describe a basic Synthesis Flow ?
2. Four Different Path Groups
* Input to Register
* Register to Register
* Register to Output
* Input to Output
3. What are wireload models ?
* Different Types of wireload Models
* Where they help and where they are inadequate
* What are default wireload models and what are custom wireload models
4. Scan Insertion
* Scan and IDDQ testing