Skip to content
Tutorials Center
My learning

Topics

Lesson 56 of 57 ยท Practice and Review

Digital Logic Interview Questions

Sixteen common digital logic interview questions with short, precise answers: latch vs flip-flop, hazards, metastability, Mealy vs Moore, K-maps and more, with live checks.

Digital logic questions show up in hardware, embedded, FPGA and computer-architecture interviews, and in exams. Interviewers rarely want a recitation of definitions. They want to hear whether you understand why a circuit behaves the way it does, and whether you can back a claim with a small example. This lesson collects sixteen of the most common questions, each with a short answer you could give out loud, and four live programs that demonstrate the trickiest ideas.

The answers are deliberately brief. If one feels shaky, follow the link to the full lesson.

How to answer well

Answer first One clear sentence, then the reason.
Draw it A tiny truth table or waveform beats a paragraph.
Name the trade-off Speed, area, power, simplicity.
1 / 2

Numbers and codes

1. Why do computers use two's complement for signed numbers? Because the same adder works for signed and unsigned values, and there is exactly one representation of zero. Negating a number is "invert the bits and add one", and subtraction becomes addition. Sign-magnitude and one's complement both have two zeros and need extra hardware. See Signed Numbers and Two's Complement.

2. What is Gray code and where is it used? A sequence in which consecutive values differ in exactly one bit. It is used where several bits might be read while changing, for example rotary encoders and passing a counter value across a clock boundary, because a mid-change read is wrong by at most one step instead of producing an arbitrary value. It also provides the cell order of a K-map. See BCD, Gray Code and ASCII.

Gates and Boolean algebra

3. Which gates are universal, and why does it matter? NAND and NOR. Each can build NOT, AND and OR, so any circuit can be made from one gate type. In CMOS, NAND and NOR are also the cheapest gates, so real designs lean on them. See Universal Gates.

4. How many different Boolean functions exist for n inputs? 2^(2^n): a function is a choice of output (0 or 1) for each of the 2^n rows of the truth table. Two inputs give 16 functions, three give 256, four give 65,536. That explosion is why simplification tools matter.

5. State De Morgan's theorems and one use. (AB)' = A' + B' and (A + B)' = A'B'. They convert AND-OR logic into NAND-NAND and let you "push bubbles" through a circuit. See De Morgan's Theorems.

Python Live check: universal gates, De Morgan and function counts

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Combinational circuits

6. Why is a ripple-carry adder slow, and how do you speed it up? Each full adder waits for the carry from the previous one, so delay grows linearly with the width. Carry-lookahead computes all carries in parallel from propagate and generate signals, trading more gates for logarithmic depth. See Half Adders and Full Adders and Carry-Lookahead.

7. What is the difference between a multiplexer and a decoder? A mux selects one of many data inputs and passes it to one output. A decoder expands an n-bit code into one of 2^n lines, producing minterms. Used together they implement any function: a decoder plus an OR gate, or a mux whose data inputs are constants and variables.

8. Why does a K-map use Gray code order on its axes? So that neighboring cells differ in exactly one variable. Adjacent 1s can then be merged and the changing variable disappears from the term. With ordinary binary order, neighbors could differ in two variables and grouping would be wrong. See Karnaugh Maps.

9. What are don't-care conditions? Input combinations that never occur or whose output does not matter. In a K-map you may treat them as 1 or 0, whichever gives larger groups, which leads to simpler logic.

10. What is a static hazard and how do you remove it? A static-1 hazard is a momentary 0 glitch on an output that should stay at 1 while one input changes, caused by unequal path delays. In F = AB + A'C with B = C = 1, when A falls the AB term turns off one gate delay before the A'C term turns on. Adding the consensus term BC covers the gap. Hazards harm asynchronous circuits and clock or enable paths; in a purely synchronous design a glitch that settles before the clock edge is harmless. See Don't-Cares and Hazards.

The simulation below gives every gate a delay of one step and falls A at step 4.

Python A static-1 hazard and the consensus term that cures it

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first block shows F dipping to 0 for one step; the second, with the extra BC term, stays at 1.

Sequential circuits

11. What is the difference between a latch and a flip-flop? A latch is level-sensitive: while its enable is active the output follows the input. A flip-flop is edge-triggered: it samples the input only at a clock edge and ignores it otherwise. A flip-flop is usually two latches in a master-slave arrangement. Flip-flops make synchronous design predictable because state changes only at defined instants. See D Latches and D Flip-Flops.

Python The same noisy data, a latch and a flip-flop

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The latch output wiggles whenever the data does during the high clock phase. The flip-flop changes at most once per clock period.

12. Explain setup and hold times. Setup time is how long the data must be stable before the clock edge; hold time is how long it must stay stable after it. A setup violation is cured by a slower clock or shorter logic. A hold violation does not depend on the clock period and is cured by adding delay. The maximum frequency satisfies T >= tcq + tlogic + tsu + skew. See Timing, Clock Skew and Metastability.

13. What is metastability and how do you deal with it? If data changes inside the setup/hold window, a flip-flop output can hover at an in-between voltage for an unpredictable time before settling to 0 or 1. You cannot eliminate it for truly asynchronous inputs; you reduce its probability. The standard cure is a synchronizer: two (or more) flip-flops in series, so the first has a full clock period to resolve before the second samples it. The mean time between failures grows exponentially with the settling time, which the program below illustrates with plausible numbers.

14. Mealy versus Moore machines? In a Moore machine the output depends only on the current state; in a Mealy machine it depends on the state and the current input. Mealy machines often need fewer states and react in the same cycle, but their outputs can change with the input asynchronously, so glitches on inputs reach the outputs. Moore outputs change only after a clock edge, which is cleaner and one cycle later. See Finite State Machines.

Python Mealy vs Moore timing, and synchronizer MTBF

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

15. Synchronous versus asynchronous (ripple) counters? In a ripple counter each flip-flop clocks the next, so delays accumulate and outputs briefly show wrong values while the change ripples. In a synchronous counter all flip-flops share one clock and extra gates decide which toggle, so all outputs change together, at the cost of more logic. See Counters.

16. Ring counter versus Johnson counter? A ring counter circulates a single 1, so n flip-flops give n states. A Johnson (twisted-ring) counter feeds back the inverted output, so n flip-flops give 2n states, and each state is decoded with just a two-input gate. See Registers and Shift Registers.

When you do not know an answer, reason from the basic structure: what is the circuit built from, and what changes when the input changes? Interviewers value that more than a half-remembered definition.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which statement best separates a latch from a flip-flop?

    Level-sensitive versus edge-triggered is the defining difference. The latch is transparent for a whole phase of the clock; the flip-flop captures once per edge.
  2. 2. How does a two-flip-flop synchronizer reduce failures?

    Metastability resolves exponentially with time. The extra period raises the settling time, and MTBF grows exponentially with it.
  3. 3. A static-1 hazard in an AND-OR circuit is removed by...

    The consensus term holds the output at 1 while the other two product terms hand over, so the glitch disappears.
  4. 4. A Mealy machine differs from a Moore machine because its output...

    Moore outputs are functions of the state alone. Mealy outputs also look at the input, so they can respond in the same cycle.
  5. 5. How many Boolean functions of 3 variables exist?

    A function assigns 0 or 1 to each of 2^3 = 8 rows, so there are 2^8 = 256 functions.

Summary

  • Know the why: two's complement shares the adder, Gray code changes one bit at a time, NAND and NOR are universal.
  • A hazard is a glitch from unequal delays; the consensus term fixes a static-1 hazard.
  • Latches are level-sensitive, flip-flops are edge-triggered; setup and hold define the safe window around the edge.
  • Metastability cannot be removed, only made rare with synchronizers; MTBF grows exponentially with settling time.
  • Moore outputs depend on the state, Mealy outputs on the state and the input.

Next: Digital Logic Cheat Sheet.