ALU & Arithmetic Operations — Two’s Complement, Booth’s Algorithm & IEEE 754 | GATE CS

ALU & Arithmetic Operations in Computer Organisation

Two’s Complement, Fast Adders, Booth’s Algorithm & IEEE 754 Floating-Point — Complete GATE CS Notes

Last updated: April 2026  |  GATE CS syllabus aligned

Key Takeaways

  • The ALU performs all arithmetic (ADD, SUB, MUL, DIV) and logical (AND, OR, XOR, NOT, shift) operations in the CPU
  • Two’s complement is the universal integer representation — the same hardware adds and subtracts, and overflow detection is simple
  • Ripple carry adder is simple but slow (O(n) delay); carry lookahead adder is fast (O(log n) delay)
  • Booth’s algorithm multiplies two signed numbers efficiently, handling long runs of 1s with fewer additions
  • IEEE 754 floating-point: value = (−1)^S × 1.M × 2^(E − bias); sign + biased exponent + implicit-1 mantissa
  • Single precision: 1 sign + 8 exponent (bias 127) + 23 mantissa = 32 bits
  • Overflow (result too large) and underflow (result too small for representation) are distinct — do not confuse them

1. ALU Structure and Operations

The Arithmetic Logic Unit (ALU) is the computational core of the CPU. It takes two operands from registers (or one operand for shifts/NOT), performs an operation selected by the control unit, and produces a result plus condition flags.

CategoryOperationsFlags Affected
ArithmeticADD, SUB, MUL, DIV, INC, DEC, NEGZero (Z), Carry (C), Overflow (V), Sign (N)
LogicalAND, OR, XOR, NOTZero (Z), Sign (N)
ShiftLeft shift, Right shift (logical/arithmetic)Carry (C), Zero (Z)
ComparisonCMP (subtract without storing result)Z, N, C, V (used for branches)

The condition flags register (also called the status register or flags register) captures properties of the last ALU result:

  • Z (Zero): result is zero
  • N (Negative/Sign): MSB of result is 1 (result is negative in two’s complement)
  • C (Carry): carry out of MSB for unsigned arithmetic
  • V (Overflow): signed arithmetic overflow — result does not fit in the register

2. Integer Number Representation

RepresentationPositive NumbersNegative NumbersRange (n bits)Zero
Sign-MagnitudeMSB = 0, remaining = magnitudeMSB = 1, remaining = magnitude−(2^(n−1) − 1) to +(2^(n−1) − 1)Two zeros (+0 and −0)
One’s ComplementSame as binaryInvert all bits of positive−(2^(n−1) − 1) to +(2^(n−1) − 1)Two zeros (+0 = 00…0, −0 = 11…1)
Two’s ComplementSame as binaryInvert all bits + 1−2^(n−1) to +(2^(n−1) − 1)Unique zero (00…0)
Excess-N (Biased)Stored value = actual value + NStored value = actual value + N (may be positive)Depends on biasStored as N

Two’s complement is universally used in modern CPUs because: (1) unique zero, (2) addition and subtraction use the same hardware, and (3) overflow detection is simple.

3. Two’s Complement — Addition & Subtraction

Two’s complement of X (n bits):
Method 1: Invert all bits of X, then add 1
Method 2: Copy bits from right up to and including the first 1; invert all remaining bits
Method 3: −X = 2^n − X (mathematical definition)

Range for n-bit two’s complement:
Minimum = −2^(n−1) (e.g., −128 for 8 bits)
Maximum = +2^(n−1) − 1 (e.g., +127 for 8 bits)

Subtraction using two’s complement:
A − B = A + (−B) = A + (two’s complement of B)
This is why subtraction uses the adder — no separate subtract hardware needed.

Example: 8-bit two’s complement

DecimalBinary (8-bit two’s complement)
+1270111 1111
+10000 0001
00000 0000
−11111 1111
−1271000 0001
−1281000 0000 (only this value has no positive counterpart)

4. Overflow Detection

Overflow rule for two’s complement addition:
Overflow occurs if and only if:
(positive + positive = negative result) OR (negative + negative = positive result)

Hardware detection: Overflow = carry into MSB ⊕ carry out of MSB
(XOR of the last two carry bits)

No overflow if:
Adding numbers of opposite signs — result is always within range
(largest positive + most negative = between them)

Overflow vs Carry:
Carry out (C) = set for unsigned overflow (result doesn’t fit in n bits, unsigned)
Overflow (V) = set for signed overflow (result doesn’t fit in n bits, signed)
They are independent — one can occur without the other.

5. Adder Types — Ripple Carry vs Carry Lookahead

Ripple Carry Adder (RCA)

Chain n full adders, each taking the carry out of the previous stage as carry in. Simple, small, but slow — carry must propagate through all n stages.

Ripple Carry Adder:
For each bit i: Sum_i = A_i ⊕ B_i ⊕ C_i
Carry_out_i = (A_i AND B_i) OR (C_i AND (A_i XOR B_i))

Total delay = n × t_full_adder (linear in number of bits)

Carry Lookahead Adder (CLA)

Compute all carries simultaneously using generate (G) and propagate (P) signals, avoiding the ripple delay.

Generate and Propagate:
G_i = A_i AND B_i (this bit generates a carry regardless of carry in)
P_i = A_i XOR B_i (this bit propagates a carry in to carry out)

Carry expressions (no ripple — all in parallel):
C_1 = G_0 + P_0 × C_0
C_2 = G_1 + P_1 × G_0 + P_1 × P_0 × C_0
C_3 = G_2 + P_2 × G_1 + P_2 × P_1 × G_0 + P_2 × P_1 × P_0 × C_0

Delay = O(log n) — much faster than RCA for wide operands

PropertyRipple CarryCarry Lookahead
SpeedO(n) — slow for wide operandsO(log n) — fast
Hardware costLow — minimal logicHigher — extra generate/propagate gates
Used inSimple/embedded designs, lower bitsHigh-performance CPUs (32/64-bit ALUs)

6. Binary Multiplication & Booth’s Algorithm

Basic Binary Multiplication

Binary multiplication uses the same principle as long multiplication: generate partial products (each bit of the multiplier either selects the multiplicand shifted left, or zero), then sum all partial products.

For n × n bit multiplication: produces up to 2n-bit result
n partial products generated; summed using a series of adders

Booth’s Algorithm

Booth’s algorithm reduces the number of add/subtract operations needed for multiplication, especially when the multiplier has long runs of 1s. It correctly handles signed (two’s complement) multiplication without special cases.

The key insight: a run of k consecutive 1s in the multiplier (e.g., 011110) can be replaced by (100000 − 000010), i.e., one addition and one subtraction rather than k additions.

Booth’s Algorithm Rules (examine current bit q_i and previous bit q_{i-1}):
q_i = 0, q_{i-1} = 0: No operation (inside a run of 0s)
q_i = 1, q_{i-1} = 1: No operation (inside a run of 1s)
q_i = 0, q_{i-1} = 1: ADD multiplicand (end of a run of 1s)
q_i = 1, q_{i-1} = 0: SUBTRACT multiplicand (start of a run of 1s)

After each step: arithmetic right shift the (accumulator + multiplier + extra bit) by 1

Booth’s Algorithm Procedure (for n-bit numbers):

  1. Initialise: Accumulator A = 0, Q = multiplier, Q_{−1} = 0
  2. Repeat n times:
    • Check Q_0 (LSB of Q) and Q_{−1}
    • If 01: A = A + multiplicand (M)
    • If 10: A = A − multiplicand (A + two’s complement of M)
    • If 00 or 11: no operation
    • Arithmetic right shift {A, Q, Q_{−1}} by 1 (shift MSB of Q into LSB of A, shift LSB of Q into Q_{−1})
  3. Result = {A, Q} (2n bits)

7. IEEE 754 Floating-Point Representation

Integer arithmetic is exact but limited in range. Floating-point represents a vast range of values by separating a number into a sign, an exponent (scaling factor), and a mantissa (significant digits).

IEEE 754 Value Formula:
Value = (−1)^S × 1.M × 2^(E − bias)
S = sign bit (0 = positive, 1 = negative)
M = mantissa (fractional part after the implicit leading 1)
E = stored exponent (biased)
bias = 2^(exponent_bits − 1) − 1

Single Precision (32-bit):
| S (1 bit) | Exponent E (8 bits) | Mantissa M (23 bits) |
bias = 127
Range: ≈ ±3.4 × 10^38, Precision: ≈ 7 decimal digits

Double Precision (64-bit):
| S (1 bit) | Exponent E (11 bits) | Mantissa M (52 bits) |
bias = 1023
Range: ≈ ±1.8 × 10^308, Precision: ≈ 15 decimal digits

Special Values in IEEE 754

ConditionStored ExponentMantissaRepresents
Zero0000 0000 (all zeros)0±0.0
Denormalised number0000 0000 (all zeros)≠ 0Very small numbers near zero (no implicit leading 1)
Normal number1 to 254 (not all 0s or all 1s)AnyRegular floating-point value
Infinity1111 1111 (all ones)0±∞ (e.g., 1.0/0.0)
NaN (Not a Number)1111 1111 (all ones)≠ 0Undefined (e.g., 0.0/0.0, √−1)

Steps to convert decimal to IEEE 754 single precision:

  1. Determine sign bit S (0 for positive, 1 for negative)
  2. Convert magnitude to binary
  3. Normalise: move binary point to get 1.xxx × 2^n
  4. Exponent stored = n + 127 (add bias)
  5. Mantissa = xxx… (the fractional part, padded to 23 bits)

8. GATE-Level Worked Examples

Example 1 — Two’s Complement Subtraction (GATE 2020)

Problem: Using 8-bit two’s complement, compute 45 − 73. State whether overflow occurs.

Solution:
45 = 0010 1101
73 = 0100 1001
−73 = invert(73) + 1 = 1011 0110 + 1 = 1011 0111

45 + (−73):
  0010 1101
+ 1011 0111
= 1110 0100

1110 0100 in two’s complement: MSB = 1, so negative.
Magnitude = invert(1110 0100) + 1 = 0001 1011 + 1 = 0001 1100 = 28
Result = −28

Overflow check: positive + negative — no overflow possible. ✓

Example 2 — Booth’s Algorithm (GATE 2022 style)

Problem: Use Booth’s algorithm to multiply +6 × (−3) using 4-bit representation.

Setup:
Multiplicand M = +6 = 0110, −M = 1010 (two’s complement)
Multiplier Q = −3 = 1101
A = 0000, Q = 1101, Q_{−1} = 0

Step 1: Q_0=1, Q_{-1}=0 → subtract M: A = 0000 + 1010 = 1010
Arithmetic right shift: A=1101, Q=0110, Q_{-1}=1

Step 2: Q_0=0, Q_{-1}=1 → add M: A = 1101 + 0110 = 0011 (carry discarded within 4 bits→ 10011, take lower 4: 0011)
Wait — 1101 + 0110 = 10011. A is 4 bits so A = 0011 with carry out.
Arithmetic right shift: A=0001, Q=1011, Q_{-1}=0 (MSB of A shifts in from sign bit 0)

Step 3: Q_0=1, Q_{-1}=0 → subtract M: A = 0001 + 1010 = 1011
Arithmetic right shift: A=1101, Q=1101, Q_{-1}=1

Step 4: Q_0=1, Q_{-1}=1 → no operation
Arithmetic right shift: A=1110, Q=1110, Q_{-1}=1

Result = {A, Q} = 1110 1110 = −18 in 8-bit two’s complement
Check: 6 × (−3) = −18

Example 3 — IEEE 754 Encoding (GATE 2021)

Problem: Represent −10.75 in IEEE 754 single precision.

Solution:
Sign = 1 (negative)

|−10.75| = 10.75
10 in binary = 1010
0.75 in binary = 0.11 (0.75 × 2 = 1.5 → 1; 0.5 × 2 = 1.0 → 1)
10.75 = 1010.11

Normalise: 1.01011 × 2^3
Exponent = 3 + 127 = 130 = 1000 0010
Mantissa = 01011 followed by 18 zeros = 010 1100 0000 0000 0000 0000 0
(23 bits total)

IEEE 754: 1 | 1000 0010 | 010 1100 0000 0000 0000 0000 0
= 0xC12C0000

9. Common Mistakes

  1. Applying two’s complement range incorrectly
    For n bits, the range is −2^(n−1) to +2^(n−1) − 1 (asymmetric). The most negative number (−128 for 8 bits) has no positive counterpart in 8 bits — negating it causes overflow. Students often forget this asymmetry and write −127 to +127.
  2. Confusing signed overflow (V flag) with carry (C flag)
    Carry out of the MSB signals unsigned overflow — the result does not fit as an unsigned number. The overflow flag (V) signals signed overflow. They are independent — it is perfectly valid to have carry without overflow (two large unsigned numbers whose signed interpretation is fine) and overflow without carry.
  3. Forgetting the implicit leading 1 in IEEE 754 normal numbers
    Normal floating-point numbers are represented as 1.M × 2^(E−bias). The leading 1 is not stored — it is implied. The mantissa bits only represent the fractional part. Forgetting this makes the precision seem 23 bits when it is actually 24 bits (23 stored + 1 implicit).
  4. Using the wrong bias in IEEE 754 exponent calculations
    Single precision bias = 127 (not 128). Double precision bias = 1023. The stored exponent = actual exponent + bias. Students sometimes confuse the formula direction — stored exponent = actual + bias, so actual = stored − bias.
  5. Arithmetic vs logical right shift
    Logical right shift fills the MSB with 0. Arithmetic right shift fills the MSB with the sign bit (extends the sign). Booth’s algorithm and two’s complement division require arithmetic right shift. Using logical shift gives the wrong result for negative numbers.

10. Frequently Asked Questions

How do you perform two’s complement subtraction?

To compute A − B: find the two’s complement of B (invert all bits and add 1), then add A + (two’s complement of B) using the regular binary adder. The carry out of the MSB is discarded for the result but is used for overflow detection. This is exactly how CPUs perform subtraction — a single adder handles both addition and subtraction by feeding in the two’s complement of the subtrahend.

What is Booth’s algorithm?

Booth’s algorithm is a signed binary multiplication technique that works directly with two’s complement numbers. It examines consecutive bit pairs of the multiplier and decides: add the multiplicand (at a 0→1 transition), subtract the multiplicand (at a 1→0 transition), or do nothing (same consecutive bits). Each step is followed by an arithmetic right shift. After n steps (for n-bit numbers), the product is in the combined accumulator+multiplier register.

What is the IEEE 754 floating-point format?

IEEE 754 is the standard for floating-point arithmetic. A 32-bit single-precision number has 1 sign bit, 8 exponent bits (stored with bias 127), and 23 mantissa bits (with an implicit leading 1). The value is (−1)^S × 1.M × 2^(E−127). Special encodings represent zero, infinity, and NaN (Not a Number). Double precision uses 64 bits: 1 sign + 11 exponent (bias 1023) + 52 mantissa.

What is the difference between ripple carry adder and carry lookahead adder?

A ripple carry adder chains n full adders — each carry must arrive at the next stage before it can compute its output, so total delay scales linearly with n bits. A carry lookahead adder computes all carry bits simultaneously using generate (G = A AND B) and propagate (P = A XOR B) signals — each carry can be computed in O(1) gates without waiting for previous stages. This gives O(log n) delay at the cost of more hardware.

Leave a Comment