Section 2 · 10 min read

Combinational circuits

Adders, carry lookahead, subtractors, comparators, multiplexers, decoders, encoders, code converters, NAND/NOR realizations and hazards, with timing and gate-count problems in GATE style.

On this page
  1. What a combinational circuit is
  2. Adders
  3. Comparators
  4. Multiplexers
  5. Decoders and encoders
  6. Code converters and parity
  7. NAND and NOR realizations
  8. Hazards
  9. Worked examples
  10. Common traps
  11. Quick revision

What a combinational circuit is

A combinational circuit has outputs that depend only on the current inputs. There is no memory and no feedback loop. Every such circuit is a set of Boolean functions, so the K-map tools from the previous topic apply directly. GATE questions here fall into four groups:

  1. Identify the function a given circuit computes (multiplexer or decoder with gates around it).
  2. Count components (how many 2-to-1 multiplexers, how many NAND gates).
  3. Timing (delay of ripple-carry versus carry-lookahead adders).
  4. Adder and subtractor behaviour, including flags.

Adders

Half adder and full adder

A half adder adds two bits: S=A⊕BS = A \oplus B, C=ABC = AB.

A full adder adds AA, BB and carry-in CinC_{in}:

S=A⊕B⊕Cin,Cout=AB+BCin+ACin=AB+Cin(A⊕B)S = A \oplus B \oplus C_{in}, \qquad C_{out} = AB + BC_{in} + AC_{in} = AB + C_{in}(A \oplus B)

CoutC_{out} is the majority function. The second form shows a full adder is two half adders plus an OR gate: the first half adder gives A⊕BA \oplus B and ABAB, the second adds CinC_{in}.

AA BB CinC_{in} SS CoutC_{out}
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1

Ripple-carry adder (RCA)

An nn-bit RCA chains nn full adders; stage ii waits for the carry from stage i−1i-1. If one stage produces its carry tct_c after its carry-in is ready and its sum tst_s after its carry-in is ready, then with all operands applied at time 0:

TRCA=(n−1) tc+max⁡(ts,tc)T_{RCA} = (n-1)\,t_c + \max(t_s, t_c)

The delay grows linearly with nn. Be careful about whether the question wants the last sum bit, the final carry, or both.

Carry-lookahead adder (CLA)

Define per bit a generate and a propagate signal:

Gi=AiBi,Pi=Ai⊕Bi,Ci+1=Gi+PiCiG_i = A_iB_i, \qquad P_i = A_i \oplus B_i, \qquad C_{i+1} = G_i + P_iC_i

Expanding the recurrence removes the chain:

Ci+1=Gi+PiGi−1+PiPi−1Gi−2+⋯+PiPi−1⋯P0C0C_{i+1} = G_i + P_iG_{i-1} + P_iP_{i-1}G_{i-2} + \cdots + P_iP_{i-1}\cdots P_0C_0

With unlimited fan-in, every carry is a two-level AND-OR expression. The usual gate-delay count is: GG and PP in 1 delay, all carries 2 delays later, sums (Pi⊕CiP_i \oplus C_i) 1 delay after that, so 4 gate delays regardless of nn. In practice fan-in is limited, so wide adders use 4-bit CLA blocks that either ripple carries between blocks or use a second level of lookahead.

PiP_i is sometimes defined as Ai+BiA_i + B_i instead of XOR. The carry equation still works with OR, but then the sum needs Ai⊕BiA_i \oplus B_i separately.

Subtraction

In 2's complement, A−B=A+B‾+1A - B = A + \overline{B} + 1. An adder-subtractor feeds each BiB_i through an XOR gate with a control MM and connects MM to C0C_0. M=0M = 0 adds; M=1M = 1 subtracts.

For unsigned subtraction with this circuit, final carry Cn=1C_n = 1 means no borrow (A≥BA \ge B), and Cn=0C_n = 0 means a borrow occurred. Signed overflow is Cn⊕Cn−1C_n \oplus C_{n-1}.

Comparators

A 1-bit equality test is XNOR. For nn-bit numbers, A=BA = B when every xi=Ai⊕Bi‾x_i = \overline{A_i \oplus B_i} is 1. For magnitude, scan from the MSB:

A>B=An−1Bn−1‾+xn−1An−2Bn−2‾+xn−1xn−2An−3Bn−3‾+⋯A > B = A_{n-1}\overline{B_{n-1}} + x_{n-1}A_{n-2}\overline{B_{n-2}} + x_{n-1}x_{n-2}A_{n-3}\overline{B_{n-3}} + \cdots

Counting fact: for two nn-bit unsigned numbers, the number of input pairs with A>BA > B is (4n−2n)/2(4^n - 2^n)/2.

Multiplexers

A 2k2^k-to-1 multiplexer (MUX) has kk select lines and outputs the data input whose index equals the select value. A 4-to-1 MUX with selects S1S0S_1S_0:

Y=S1‾ S0‾I0+S1‾S0I1+S1S0‾I2+S1S0I3Y = \overline{S_1}\,\overline{S_0}I_0 + \overline{S_1}S_0I_1 + S_1\overline{S_0}I_2 + S_1S_0I_3

Implementing functions with a MUX

  • A 2n2^n-to-1 MUX implements any nn-variable function: put the variables on the selects and the truth-table column on the data inputs (0s and 1s).
  • A 2n−12^{n-1}-to-1 MUX implements any nn-variable function if the last variable and its complement are available: for each select value, the data input is one of 00, 11, xx, x‾\overline{x}.
  • A single 2-to-1 MUX with constants can build NOT, AND and OR, so the 2-to-1 MUX is functionally complete. Without complemented inputs, it cannot build XOR in one unit.

MUX trees

To build an NN-to-1 MUX from mm-to-1 MUXes, divide repeatedly: ⌈N/m⌉\lceil N/m \rceil at the first level, then ⌈that/m⌉\lceil \text{that}/m \rceil, and so on down to 1. For 2-to-1 MUXes, an NN-to-1 tree needs N−1N - 1 units.

Demultiplexers

A 1-to-2k2^k demultiplexer sends one input to the output selected by kk lines. It is a decoder whose enable is the data input.

Decoders and encoders

An nn-to-2n2^n decoder activates exactly one output: output ii is minterm mim_i. Any function in sum-of-minterms form is a decoder plus an OR gate on the needed outputs (or a NOR or NAND on the others, for active-low parts).

Building larger decoders: a kk-to-2k2^k decoder with enables can be expanded into an nn-to-2n2^n decoder using a tree. For 6-to-64 from 3-to-8 units: one decoder takes the top 3 bits and enables one of 8 decoders that take the bottom 3 bits, total 9.

An encoder does the reverse: 2n2^n inputs, one of which is active, produce an nn-bit index. A priority encoder handles several active inputs by reporting the highest-priority one and adds a valid bit VV that is 0 when no input is active.

Code converters and parity

  • Binary to Gray: gn−1=bn−1g_{n-1} = b_{n-1}, gi=bi+1⊕big_i = b_{i+1} \oplus b_i. In one line, G=B⊕(B≫1)G = B \oplus (B \gg 1).
  • Gray to binary: bn−1=gn−1b_{n-1} = g_{n-1}, bi=bi+1⊕gib_i = b_{i+1} \oplus g_i. Each binary bit is the XOR of all Gray bits from the MSB down to that position.
  • BCD to excess-3: add 00110011. Excess-3 is self-complementing: the 9's complement of a digit is its bitwise inverse.
  • Parity of nn bits needs n−1n - 1 two-input XOR gates (a chain or a tree; a tree has depth ⌈log⁡2n⌉\lceil \log_2 n \rceil).

NAND and NOR realizations

NAND and NOR are each universal. Useful minimum gate counts with two-input gates and only uncomplemented inputs:

Function Two-input NAND gates Two-input NOR gates
NOT 1 1
AND 2 3
OR 3 2
XOR 4 5
XNOR 5 4
Half adder (sum and carry) 5 5

A two-level AND-OR circuit becomes a two-level NAND-NAND circuit directly (same structure, every gate replaced by NAND). Likewise OR-AND becomes NOR-NOR.

Hazards

A static-1 hazard is a momentary 0 on an output that should stay 1 when one input changes. In a K-map it shows up as two adjacent 1-cells that are covered by different product terms with no single term covering both. The fix is to add the consensus term that bridges the two groups. Static-0 hazards are the dual for POS circuits. Hazards matter for asynchronous circuits; synchronous designs sample after the outputs settle.

Worked examples

Worked example 1: Function from a 4-to-1 MUX

Implement F(A,B,C)=Σm(0,2,3,5)F(A,B,C) = \Sigma m(0,2,3,5) with a 4-to-1 MUX, using AA (MSB) and BB as selects.

Solution. For each ABAB, look at the two minterms that differ only in CC.

ABAB Minterms FF for C=0C=0, C=1C=1 Data input
00 0, 1 1, 0 I0=C‾I_0 = \overline{C}
01 2, 3 1, 1 I1=1I_1 = 1
10 4, 5 0, 1 I2=CI_2 = C
11 6, 7 0, 0 I3=0I_3 = 0

So I0=C‾I_0 = \overline{C}, I1=1I_1 = 1, I2=CI_2 = C, I3=0I_3 = 0. Reverse problems (given the data inputs, find FF) use the same table read backwards.

Worked example 2: RCA delay

A 16-bit RCA uses full adders with carry delay 2 ns and sum delay 3 ns (each measured from carry-in valid). When are all outputs valid?

Solution. Carry into stage 15 is valid at 15×2=3015 \times 2 = 30 ns. Then S15S_{15} is valid at 33 ns and C16C_{16} at 32 ns. All outputs: 33 ns. Using the formula, (16−1)⋅2+max⁡(3,2)=33(16-1) \cdot 2 + \max(3, 2) = 33.

Worked example 3: Block CLA timing

A 32-bit adder uses eight 4-bit CLA blocks, with the carry rippling from block to block. Within a block, GG and PP take 1 gate delay, each carry takes 2 gate delays after the block's GG, PP and carry-in are ready, and each sum takes 1 gate delay after its carry. Find the delay until all sums are valid.

Solution.

  • All GiG_i, PiP_i are ready at time 1.
  • Block 0 carry-out (C4C_4): 1+2=31 + 2 = 3.
  • Each later block adds 2 to its carry-out: block kk produces its carry-out at 3+2k3 + 2k.
  • Block 7 receives C28C_{28} from block 6 at 3+2⋅6=153 + 2 \cdot 6 = 15.
  • Block 7 internal carries C29,C30,C31C_{29}, C_{30}, C_{31} (and C32C_{32}) are ready at 15+2=1715 + 2 = 17.
  • Sums S29S_{29} to S31S_{31} are ready at 17+1=1817 + 1 = 18.

All sums are valid after 18 gate delays. A plain 32-bit RCA with 2 gate delays per carry would take about 64.

Worked example 4: Half adder from NAND gates

What is the minimum number of two-input NAND gates for a half adder?

Solution. XOR needs 4 NAND gates: G1=AB‾G_1 = \overline{AB}, G2=AG1‾G_2 = \overline{AG_1}, G3=BG1‾G_3 = \overline{BG_1}, S=G2G3‾S = \overline{G_2G_3}. The carry ABAB is the complement of G1G_1, which one more NAND (used as an inverter) produces. Total 5. Sharing G1G_1 between the sum and the carry is what keeps it at 5 instead of 6.

Worked example 5: Finding and fixing a hazard

F=A‾B+ACF = \overline{A}B + AC. Find the hazard and fix it.

Solution. With B=C=1B = C = 1, F=A‾+A=1F = \overline{A} + A = 1. When AA changes, one term turns off and the other turns on; if the inverter producing A‾\overline{A} is slow, both terms can be 0 briefly, and FF glitches. The consensus term of A‾B\overline{A}B and ACAC is BCBC. The hazard-free form is F=A‾B+AC+BCF = \overline{A}B + AC + BC, which is logically the same function.

Common traps

  • Confusing which select line is the MSB. Swapping S1S_1 and S0S_0 permutes the data inputs.
  • Counting MUX trees as N/m+1N/m + 1 without recursing. For 64-to-1 from 4-to-1 the answer is 16+4+1=2116 + 4 + 1 = 21.
  • Forgetting the last sum delay in RCA problems, or adding it to the final carry instead of taking the maximum.
  • Using CnC_n as signed overflow. Signed overflow is Cn⊕Cn−1C_n \oplus C_{n-1}.
  • Treating the carry-out of A+B‾+1A + \overline{B} + 1 as a borrow. A carry of 1 means no borrow.
  • Assuming a 2-to-1 MUX cannot implement NOT. With I0=1I_0 = 1 and I1=0I_1 = 0 it can.
  • In decoder-based designs, using active-high logic on an active-low decoder.

Quick revision

  • Full adder: S=A⊕B⊕CS = A \oplus B \oplus C, Cout=AB+C(A⊕B)C_{out} = AB + C(A \oplus B).
  • RCA delay: (n−1)tc+max⁡(ts,tc)(n-1)t_c + \max(t_s, t_c). CLA: about 4 gate delays with unlimited fan-in.
  • Ci+1=Gi+PiCiC_{i+1} = G_i + P_iC_i, Gi=AiBiG_i = A_iB_i, Pi=Ai⊕BiP_i = A_i \oplus B_i.
  • Subtract with A+B‾+1A + \overline{B} + 1; signed overflow =Cn⊕Cn−1= C_n \oplus C_{n-1}.
  • 2n−12^{n-1}-to-1 MUX plus the last variable and its complement gives any nn-variable function.
  • NN-to-1 from 2-to-1 MUXes: N−1N - 1 units.
  • Decoder output ii = minterm mim_i; decoder plus OR gives any SOP.
  • XOR: 4 NAND or 5 NOR. Half adder: 5 NAND.
  • Gray: G=B⊕(B≫1)G = B \oplus (B \gg 1). Parity of nn bits: n−1n - 1 XOR gates.
  • Static-1 hazard fix: add the consensus term.

Further reading

Test this section