G27
Self-checkedTier 1 16 min readdl.adders-subtractors

Adders and subtractors

Half and full adders and subtractors, the ripple-carry adder and its delay, carry lookahead, the adder-subtractor with overflow detection, the incrementer and the BCD adder.

Why it exists

Arithmetic in a computer is built from a handful of gates. The adder is the heart of the ALU: subtraction, comparison, address calculation, incrementing the program counter and even multiplication all use it. GATE asks for the equations of the half and full adder, the number of gates, the delay of a ripple-carry adder compared with carry lookahead, how an adder becomes a subtractor and where the overflow bit comes from, and how a BCD adder corrects a binary sum.

Prerequisites

You need the design procedure from combinational design and the meaning of carry and overflow from fixed-point arithmetic.

Precise definitions

Half adder. Adds two bits AA and BB. Sum S=A⊕BS = A \oplus B, carry C=ABC = AB. Cost: 1 XOR and 1 AND. It cannot take a carry from a lower position.

Full adder. Adds three bits AA, BB and the 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 of the three inputs. A full adder is two half adders (the first adds AA and BB, the second adds the carry in to that sum) and an OR gate for the two carries: 2 XOR + 2 AND + 1 OR = 5 gates.

Generate and propagate. Define G=ABG = AB (this position generates a carry whatever comes in) and P=A⊕BP = A \oplus B (it propagates an incoming carry). Then Cout=G+P CinC_{out} = G + P\,C_{in} and S=P⊕CinS = P \oplus C_{in}. (Some books use P=A+BP = A + B; the carry is the same.)

Ripple-carry adder. nn full adders in a row, the carry out of bit ii feeding the carry in of bit i+1i + 1. It is cheap (nn full adders, 5n5n gates) but the carry has to travel through all the stages: the delay grows linearly with nn. In the model where every gate takes one unit and P,GP, G are ready after one unit, each stage adds two units (AND, then OR) to the carry, so carry ckc_k is ready after 2k+12k + 1 units and the last sum bit about 2n2n units.

Carry lookahead. Instead of waiting, compute every carry directly from the PP's, the GG's and c0c_0. For four bits:

c1=G0+P0c0c_1 = G_0 + P_0 c_0 c2=G1+P1G0+P1P0c0c_2 = G_1 + P_1 G_0 + P_1 P_0 c_0 c3=G2+P2G1+P2P1G0+P2P1P0c0c_3 = G_2 + P_2 G_1 + P_2 P_1 G_0 + P_2 P_1 P_0 c_0 c4=G3+P3G2+P3P2G1+P3P2P1G0+P3P2P1P0c0c_4 = G_3 + P_3 G_2 + P_3 P_2 G_1 + P_3 P_2 P_1 G_0 + P_3 P_2 P_1 P_0 c_0

Each is a two-level AND-OR circuit, so in the same model all carries are ready after 3 units (P,GP, G at 1, AND at 2, OR at 3) and the sums after 4, independent of the number of bits in the group. The price is more gates with larger fan-in. For wide words, lookahead is applied in groups (a second level of lookahead on group PP and GG).

Half subtractor. A−BA - B: difference D=A⊕BD = A \oplus B, borrow out Bout=A′BB_{out} = A'B. Full subtractor A−B−BinA - B - B_{in}:

D=A⊕B⊕Bin,Bout=A′B+A′Bin+B Bin.D = A \oplus B \oplus B_{in},\qquad B_{out} = A'B + A'B_{in} + B\,B_{in}.

Adder-subtractor. To subtract, use A−B=A+Bˉ+1A - B = A + \bar{B} + 1 (2's complement). One nn-bit adder with an XOR gate on each bit of BB and a control input MM:

  • each BiB_i goes through Bi⊕MB_i \oplus M,
  • MM is also the carry into bit 0.

M=0M = 0 adds (A+BA + B) and M=1M = 1 subtracts (A+Bˉ+1A + \bar{B} + 1). The carry out is 1 for a subtraction exactly when A≥BA \ge B as unsigned numbers (no borrow). Overflow of the signed operation is V=cn−1⊕cnV = c_{n-1} \oplus c_n (the carries into and out of the sign bit).

Incrementer. A chain of half adders adds 1: Si=Ai⊕ciS_i = A_i \oplus c_i, ci+1=Aicic_{i+1} = A_i c_i with c0=1c_0 = 1.

BCD adder. Adds two BCD digits (and a carry in) and gives a BCD digit and a carry. Procedure: add the digits and the carry in with a 4-bit binary adder, giving the 4-bit binary sum Z8Z4Z2Z1Z_8 Z_4 Z_2 Z_1 and a carry out KK. If the true sum is more than 9, add 6 (0110) to correct the digit and produce a decimal carry. The correction is needed exactly when

carry=K+Z8Z4+Z8Z2.\text{carry} = K + Z_8 Z_4 + Z_8 Z_2 .

The correction adds 6 because a 4-bit binary digit holds 16 values while a decimal digit uses 10: adding 6 skips the six unused codes and produces the carry into the next digit.

How it works

Step through a 4-bit ripple-carry addition. Each step is one full adder: the three input bits, the sum bit and the new carry. Unknown positions are shown as dots; they are filled in from the right, which is exactly what the circuit does and why the carry limits the speed.

Ripple-carry addition: 1011 + 0110: Set up

Computed exactly, not typed

Working

A = 1011
B = 0110
M = 0 (carry into bit 0)

Value, format and bits (changed bits in amber)

Aunsigned= 11
1011
Bunsigned= 6
0110
carries c4 ... c0carry chain= known so far
....0
sum S3 ... S0partial= known so far
....

Step 1

Add two 4-bit numbers with four full adders in a row. The carry out of each full adder is the carry into the next one, so the carry has to ripple from bit 0 to bit 3.

1 / 6
computed by script: exact integer, Fraction and truth-table evaluation (IEEE 754 patterns via Python struct where used), not typed by hand. Python 3.15.1, darwin arm64. python3 scripts/gen-dl-traces.py

The adder becomes a subtractor by feeding the inverted BB and setting the carry in to 1. Here is 7−57 - 5: the third row is BB XOR MM with M=1M = 1.

Adder-subtractor: 0111 - 0101 as 0111 + 1010 + 1: Set up

Computed exactly, not typed

Working

A = 0111
B = 0101
M = 1 (carry into bit 0)

Value, format and bits (changed bits in amber)

Aunsigned= 7
0111
Bunsigned= 5
0101
B xor M (M = 1)unsigned= 10
1010
carries c4 ... c0carry chain= known so far
....1
sum S3 ... S0partial= known so far
....

Step 1

The control input M = 1 turns the adder into a subtractor: every bit of B is XORed with M, and M is also the carry into bit 0, so the adder computes A + (not B) + 1 = A - B.

1 / 6
computed by script: exact integer, Fraction and truth-table evaluation (IEEE 754 patterns via Python struct where used), not typed by hand. Python 3.15.1, darwin arm64. python3 scripts/gen-dl-traces.py

The full adder's equations are visible in its truth table: the carry out is the majority of the inputs, and it equals G+P CinG + P\,C_{in}.

Full adder: carry out as majority, and as G + P.Cin

Computed exactly, not typed
ABCinP=A xor BG=ABSCout=AB+BCin+ACinG+P.Cin
000·····
001·····
010·····
011·····
100·····
101·····
110·····
111·····

Step 0

Claim: the carry out of a full adder is the majority of its three inputs, and it also equals G + P Cin, where G = AB generates a carry and P = A xor B propagates an incoming one. The sum is P xor Cin.

0 / 9
computed by script: exact integer, Fraction and truth-table evaluation (IEEE 754 patterns via Python struct where used), not typed by hand. python3 scripts/gen-dl-traces.py

Worked examples

EX 1The full adder, in a program

Easy

The program models a full adder with PP and GG, builds a 4-bit adder-subtractor from it, and checks the ripple adder, the subtractor, the carry-lookahead carries and a BCD adder against ordinary integer arithmetic for every input.

#include <stdio.h>
 
typedef struct { int sum, cout; } Fa;
 
static Fa full_adder(int a, int b, int cin) {
    int p = a ^ b, g = a & b;
    Fa r = { p ^ cin, g | (p & cin) };
    return r;
}
 
/* 4-bit ripple-carry adder-subtractor: mode 0 adds, mode 1 subtracts (b is XORed with mode, mode is the carry in) */
static unsigned add_sub4(unsigned a, unsigned b, int mode, int *cout, int *carry_into_sign) {
    unsigned s = 0;
    int c = mode;
    for (int i = 0; i < 4; i++) {
        if (i == 3) *carry_into_sign = c;
        Fa r = full_adder((a >> i) & 1, ((b >> i) & 1) ^ mode, c);
        s |= (unsigned)r.sum << i;
        c = r.cout;
    }
    *cout = c;
    return s;
}
 
/* 4-bit carry-lookahead carries from p, g and c0 */
static int cla_carry(unsigned a, unsigned b, int c0, int k) {
    int c = c0;
    for (int i = 0; i < k; i++) {
        int p = ((a ^ b) >> i) & 1, g = ((a & b) >> i) & 1;
        c = g | (p & c);
    }
    return c;
}
 
int main(void) {
    int bad_add = 0, bad_sub = 0, bad_cla = 0, bad_bcd = 0;
    for (unsigned a = 0; a < 16; a++)
        for (unsigned b = 0; b < 16; b++) {
            int co, cs;
            for (int cin = 0; cin < 2; cin++) {
                unsigned t = a + b + (unsigned)cin;
                int c = cin;
                unsigned s = 0;
                for (int i = 0; i < 4; i++) {
                    Fa r = full_adder((a >> i) & 1, (b >> i) & 1, c);
                    s |= (unsigned)r.sum << i;
                    c = r.cout;
                }
                bad_add += s != (t & 15) || c != (int)(t >> 4);
                for (int k = 1; k <= 4; k++) {
                    unsigned lo = (1u << k) - 1;
                    bad_cla += cla_carry(a, b, cin, k) != (int)(((a & lo) + (b & lo) + (unsigned)cin) >> k);
                }
            }
            unsigned d = add_sub4(a, b, 1, &co, &cs);
            bad_sub += d != ((a - b) & 15) || co != (a >= b);
        }
    for (int x = 0; x < 10; x++)
        for (int y = 0; y < 10; y++)
            for (int cin = 0; cin < 2; cin++) {
                int z = x + y + cin;
                int carry = z > 15;
                int s4 = z & 15;
                int fix = carry || s4 > 9;
                int res = fix ? s4 + 6 : s4;
                int tens = fix ? 1 : 0, ones = res & 15;
                bad_bcd += tens * 10 + ones != x + y + cin;
            }
    printf("ripple add wrong: %d, subtract wrong: %d, lookahead wrong: %d, BCD wrong: %d\n", bad_add, bad_sub, bad_cla, bad_bcd);
    int co, cs;
    unsigned s = add_sub4(11, 6, 0, &co, &cs);
    printf("1011 + 0110 = %u%u%u%u%u (carry out %d)\n", (unsigned)co, (s >> 3) & 1, (s >> 2) & 1, (s >> 1) & 1, s & 1, co);
    s = add_sub4(7, 5, 1, &co, &cs);
    printf("7 - 5 = %u with carry out %d (no borrow)\n", s, co);
    s = add_sub4(5, 7, 1, &co, &cs);
    printf("5 - 7 = %u (%d signed) with carry out %d (borrow)\n", s, (int)s - 16, co);
    s = add_sub4(7, 1, 0, &co, &cs);
    printf("7 + 1 = %u, carry into sign %d, carry out %d, overflow %d\n", s, cs, co, cs ^ co);
    return 0;
}
ripple add wrong: 0, subtract wrong: 0, lookahead wrong: 0, BCD wrong: 0
1011 + 0110 = 10001 (carry out 1)
7 - 5 = 2 with carry out 1 (no borrow)
5 - 7 = 14 (-2 signed) with carry out 0 (borrow)
7 + 1 = 8, carry into sign 1, carry out 0, overflow 1

The first line is a check over all inputs (no mismatches). The following lines are the examples that the animations step through, and the overflow case: 7+1=87 + 1 = 8 does not fit in a signed 4-bit number (maximum 7), and the XOR of the last two carries, 1⊕01 \oplus 0, flags it.

EX 2Count the gates of a full adder

Easy

From the half-adder form: 2 XOR gates (A⊕BA \oplus B and then ⊕Cin\oplus C_{in}), 2 AND gates (ABAB and (A⊕B)Cin(A \oplus B)C_{in}) and 1 OR gate for the carry: 5 gates. A 4-bit ripple adder with a full adder in every position has 4×5=204 \times 5 = 20 gates; with a half adder in position 0 (when there is no carry in) it has 3×5+2=173 \times 5 + 2 = 17 gates.

EX 3Subtract with the adder-subtractor

Medium

Compute 7−57 - 5 with M=1M = 1.

Step 1. B=0101B = 0101, B⊕M=1010B \oplus M = 1010, carry in 1. The animation shows each bit.

Step 2. 0111+1010+1=1 00100111 + 1010 + 1 = 1\,0010. The 4-bit result is 0010=20010 = 2.

Step 3. The carry out is 1, which for a subtraction means no borrow (7≥57 \ge 5).

For 5−75 - 7 the program shows the result 1110=141110 = 14 unsigned, which is −2-2 in 2's complement, and a carry out of 0, which means a borrow was needed.

EX 4Overflow detection in the adder-subtractor

Medium

7+17 + 1 in 4-bit 2's complement: 0111+0001=10000111 + 0001 = 1000. The carry into the sign bit is 1 and the carry out is 0, so V=1⊕0=1V = 1 \oplus 0 = 1: overflow. The result 10001000 reads as −8-8 instead of the true +8+8. In contrast −1+1-1 + 1 has carry in 1 and carry out 1, so V=0V = 0.

EX 5Carry-lookahead carries by hand

Medium

Add A=1011A = 1011 and B=0110B = 0110 with c0=0c_0 = 0. G=AB=0010G = AB = 0010 (bit by bit: G0=0G_0 = 0, G1=1G_1 = 1, G2=0G_2 = 0, G3=0G_3 = 0) and P=A⊕B=1101P = A \oplus B = 1101 (P0=1P_0 = 1, P1=0P_1 = 0, P2=1P_2 = 1, P3=1P_3 = 1).

Carries. c1=G0+P0c0=0c_1 = G_0 + P_0 c_0 = 0. c2=G1+P1G0+P1P0c0=1c_2 = G_1 + P_1 G_0 + P_1 P_0 c_0 = 1. c3=G2+P2G1+⋯=0+1⋅1=1c_3 = G_2 + P_2 G_1 + \cdots = 0 + 1\cdot 1 = 1. c4=G3+P3G2+P3P2G1+⋯=0+0+1⋅1⋅1=1c_4 = G_3 + P_3 G_2 + P_3 P_2 G_1 + \cdots = 0 + 0 + 1 \cdot 1 \cdot 1 = 1.

Sums. Si=Pi⊕ciS_i = P_i \oplus c_i: S0=1⊕0=1S_0 = 1 \oplus 0 = 1, S1=0⊕0=0S_1 = 0 \oplus 0 = 0, S2=1⊕1=0S_2 = 1 \oplus 1 = 0, S3=1⊕1=0S_3 = 1 \oplus 1 = 0. So the sum is 00010001 with carry out 1, the same as the ripple animation 11+6=1711 + 6 = 17, and every carry was computed without waiting for the previous one.

EX 6Ripple against lookahead delay

GATE level

In the model "every gate is one unit, PP and GG ready after one unit": the 4-bit ripple adder has c4c_4 ready after 2⋅4+1=92 \cdot 4 + 1 = 9 units (the animation's carry chain, c1c_1 at 3, c2c_2 at 5, c3c_3 at 7, c4c_4 at 9) and the last sum bit after 8; the 4-bit carry-lookahead adder has all carries after 3 units and all sums after 4. For a 32-bit ripple adder the last carry takes 2⋅32+1=652 \cdot 32 + 1 = 65 units. The lookahead adder avoids this growth but needs gates with up to n+1n + 1 inputs, which is why wide adders use groups of 4 bits and a second lookahead level.

Always read the question's own delay figures (it may give the delays of AND, OR and XOR separately, or say the carry delay per stage).

EX 7BCD addition with correction

GATE level

8+78 + 7. Binary: 1000+0111=1111=151000 + 0111 = 1111 = 15, K=0K = 0. Z=1111Z = 1111 has Z8Z4=1Z_8 Z_4 = 1, so the correction condition holds (15 is more than 9). Add 6: 1111+0110=1 01011111 + 0110 = 1\,0101, giving the decimal carry 1 and the digit 5: 1515.

9+99 + 9. Binary: 1001+1001=1 00101001 + 1001 = 1\,0010: K=1K = 1 and Z=0010Z = 0010. K=1K = 1, so correct: 0010+0110=10000010 + 0110 = 1000, digit 8, decimal carry 1: 1818.

4+34 + 3. 0100+0011=0111=70100 + 0011 = 0111 = 7. K=0K = 0, Z8=0Z_8 = 0, so no correction: digit 7, carry 0.

The program checks the whole procedure for all digit pairs and both carry-ins. The largest BCD sum is 9+9+1=199 + 9 + 1 = 19.

Cheat box

Cheat box

  • Half adder: S=A⊕BS = A \oplus B, C=ABC = AB (2 gates). Full adder: S=A⊕B⊕CinS = A \oplus B \oplus C_{in}, Cout=AB+Cin(A⊕B)C_{out} = AB + C_{in}(A \oplus B) = majority (5 gates).
  • G=ABG = AB, P=A⊕BP = A \oplus B, ci+1=Gi+Picic_{i+1} = G_i + P_i c_i, Si=Pi⊕ciS_i = P_i \oplus c_i.
  • Ripple adder: nn full adders; delay grows linearly with nn. Lookahead: all carries from PP, GG, c0c_0 in two levels; delay independent of nn within a group.
  • Half subtractor: D=A⊕BD = A \oplus B, Bout=A′BB_{out} = A'B. Full subtractor: D=A⊕B⊕BinD = A \oplus B \oplus B_{in}, Bout=A′B+A′Bin+BBinB_{out} = A'B + A'B_{in} + B B_{in}.
  • Adder-subtractor: XOR each BiB_i with MM, carry in =M= M. Carry out =1= 1 means no borrow when subtracting.
  • Overflow V=cn−1⊕cnV = c_{n-1} \oplus c_n.
  • Incrementer: chain of half adders. BCD adder: add, then +6+6 if sum >9> 9 or carry; condition K+Z8Z4+Z8Z2K + Z_8Z_4 + Z_8Z_2.

Traps and GATE patterns

Connections

The adder-subtractor, with its flags, is the arithmetic core of the ALU. The signed interpretation of the result and the meaning of CC and VV come from signed number representation and fixed-point arithmetic. The gates used are those of logic gates (the XOR especially), and the digit code that the BCD adder works on is in codes.

PYQs

7 previous year questions from your book. I re-solved each one myself (5 by running or simulating, 2 by reasoning only); the book's key is shown next to my answer. All PYQs

GATE 2006 · MCQQ31 · page 156 of the book
We consider the addition of two 2's complement
numbers bn-1 bn-2 ... b0 and an-1 an-2 ... a0. A binary
adder for adding unsigned binary numbers is used to
add the two numbers. The sum is denoted by cn-1 cn-2
... c0 and the carry-out by cout. Which one of the
following options correctly identifies the overflow
condition?
  • (a)cout ( an-1 ⊕bn-1̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅)
  • (b)an-1 bn-1cn-1̅̅̅̅̅̅ + an-1̅̅̅̅̅̅ bn-1̅̅̅̅̅̅ cn-1
  • (c)cout ⊕ cn-1
  • (d)an-1 ⊕ bn-1 ⊕ cn-1
GATE 2016 · Set 2 · NAT · 1 markQ8 · page 175 of the book
Consider an eight-bit ripple-carry adder for
computing the sum of A and B, where A and B are
integers represented in 2's complement form. If the
decimal value of A is one, the decimal value of B that
leads to the longest latency for the sum to stabilize is
______.
GATE 2016 · Set 1 · MCQQ9 · page 175 of the book
Consider a carry look ahead adder for adding two n-
bit integers, built using gates of fan-in at most two.
The time to perform addition using this adder is:
  • (a)Θ(1)
  • (b)Θ(log(n))
  • (c)Θ(√n)
  • (d)Θ(n) DIGITAL LOGIC
GATE 2015 · Set 2 · NAT · 1 markQ10 · page 176 of the book
A half adder is implemented with XOR and AND
gates. A full adder is implemented with two half
adders and one OR gate. The propagation delay of
an XOR gate is twice that of an AND/OR gate. The
propagation delay of an AND/OR gate is 1.2
microseconds. A 4-bit ripple-carry binary adder is
implemented by using four full adders. The total
propagation time of this 4-bit binary adder in
microseconds is ______.
GATE 2009 · MCQ · 1 markQ16 · page 177 of the book
Which one of the following adders reduces carry
propagation delay by generating carries in
advance?
  • (a)Ripple Carry Adder
  • (b)Carry Lookahead Adder
  • (c)Serial Adder
  • (d)Half Adder
GATE 2007 · MCQQ18 · page 177 of the book
In a look-ahead carry generator, the carry generates
function Gi and the carry propagate function Pi for
inputs Ai and Bi are given by:

Pi = Ai ⊕ Bi and Gi = AiBi

The expressions for the sum bit Si and the carry bit
Ci+1 of the look ahead carry adder are given by:

Si = Pi ⊕ Ci and Ci+1 = Gi + PiCi, where C0 is the input
carry.

Consider a two-level logic implementation of the
look-ahead carry generator. Assume that all Pi are
available for the carry generator circuit and that the
AND and OR gates can have any number of inputs.
The number of AND gates and OR gates needed to
implement the look-ahead carry generator for a 4-bit
adder with S3, S2, S1, S0 and C4 as its outputs are
respectively:
  • (a)6,3
  • (b)10,4
  • (c)6,4
  • (d)10,5
GATE 2006 · MCQ · 1 markQ21 · page 178 of the book
Given two three-bit numbers a2 a1 a0 and b2 b1 b0
and c the carry in, the function that represents the
carry generate function when these two numbers
are added is:
  • (a)a2b2 + a2a1b1 + a2a1a0b0 + a2a0b1b0 + a1b2b1 + a1a0b2b0 + a0b2b1b0
  • (b)a2b2 + a2b1b0 + a2a1b1b0 + a1a0b2b1 + a1a0b2 + a1a0b2b0 + a2a0b1b0
  • (c)a2 + b2 + (a2 ⊕ b2) (a1 + b1 + (a1 ⊕ b1)(a0 + b0))
  • (d)a2b2 + a̅2a1b1 + a̅2a1a0b0 + a̅2a0b1b0 + a1b2b1 + a̅1a0b2b0 + a0b2b1b0

Self-check

Question 1

How many full adders and how many gates does a 16-bit ripple-carry adder have if every full adder is built from 2 XOR, 2 AND and 1 OR?

Show answer

16 full adders and 16×5=8016 \times 5 = 80 gates.

Question 2

For A=0110A = 0110, B=0011B = 0011, c0=0c_0 = 0 compute GG, PP and c2c_2.

Show answer

G=AB=0010G = AB = 0010, P=A⊕B=0101P = A \oplus B = 0101. c1=G0+P0c0=0c_1 = G_0 + P_0 c_0 = 0. c2=G1+P1G0+P1P0c0=1+0+0=1c_2 = G_1 + P_1 G_0 + P_1 P_0 c_0 = 1 + 0 + 0 = 1.

Question 3

In a 4-bit adder-subtractor with M=1M = 1, A=0011A = 0011 and B=0101B = 0101. What are the result, the carry out and the overflow?

Show answer

B⊕M=1010B \oplus M = 1010, carry in 1: 0011+1010+1=11100011 + 1010 + 1 = 1110 with no carry out. The result 11101110 is −2-2 in 2's complement (3 - 5), and the carry out 0 means a borrow was needed. The low three bits give 011+010+1=110011 + 010 + 1 = 110, which does not carry into the sign bit, so the carry into the sign bit is 0 and V=0⊕0=0V = 0 \oplus 0 = 0: no overflow.

Question 4

A BCD adder adds the digits 6 and 7 with carry in 0. What are the binary sum, the corrected digit and the decimal carry?

Show answer

0110+0111=11010110 + 0111 = 1101 (13), K=0K = 0 and Z8Z4=1Z_8 Z_4 = 1, so correct: 1101+0110=1 00111101 + 0110 = 1\,0011: digit 0011=30011 = 3, decimal carry 1. The result is 13.

Revision card

One-screen revision

  • Full adder: S=A⊕B⊕CS = A \oplus B \oplus C, Cout=AB+C(A⊕B)C_{out} = AB + C(A \oplus B); 5 gates. Half adder: XOR and AND.
  • G=ABG = AB, P=A⊕BP = A \oplus B; ripple delay ∝n\propto n; lookahead carries in two levels.
  • Subtract: XOR BB with MM, carry in MM. Carry out 1 is no borrow. V=cn−1⊕cnV = c_{n-1} \oplus c_n.
  • Full subtractor: D=A⊕B⊕BinD = A \oplus B \oplus B_{in}, Bout=A′B+A′Bin+BBinB_{out} = A'B + A'B_{in} + B B_{in}.
  • BCD adder: binary add, then +6+6 when sum >9> 9 (K+Z8Z4+Z8Z2K + Z_8Z_4 + Z_8Z_2).

References

  • ·Mano and Ciletti, Digital Design, 5th ed., Chapter 4 Combinational Logic (binary adder-subtractor, carry propagation, decimal adder)
  • ·Patterson and Hennessy, Computer Organization and Design, Chapter 3 Arithmetic for Computers (constructing an ALU, carry lookahead)

Verification

The full adder, half subtractor, full subtractor and carry-lookahead equations, the n-bit ripple adder (all operands, n up to 6), the adder-subtractor (result, carry equals no borrow, and overflow for n = 3, 4, 5), the incrementer and the BCD correction condition are checked in scripts/enum-checks/dl_arith.py. The ripple-carry animations are computed by scripts/gen-dl-traces.py and recomputed independently in tests/dl-traces.test.ts. The C program is compiled and run by npm run verify:c. The gate-level delay counts use a stated model (every gate one unit) and may differ from a GATE question's own model. Textbook chapter titles are from memory; the independent second pass has not been run, so the page stays draft. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (conversions, signed ranges and flags, IEEE 754 fields and custom formats, Boolean identities and counts, K-map groups, adder carries, BCD correction, flip-flop conversions, counter sequences and T equations, state reduction, Quine-McCluskey rounds and covers, floating-point alignment and rounding); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose); tables and animations are machine output and were read, not re-run; No other defect found. Status raised to self-checked; verified needs a textbook or human check.

last verified: never