Arithmetic: adders, subtractors, multipliers, dividers and IEEE-754 — how the ALU is really built.
The Arithmetic Logic Unit is a combinational circuit and the computational heart of every CPU — everything the processor does passes through it.
The design issues of a 1-bit ALU slice: the control signals S₁ S₀ choose which operation the slice performs, and a 4×1 multiplexer picks the result. A 4-bit ALU is built by combining four 1-bit slices (carries rippling between the ADD blocks); a 16-bit ALU repeats the same idea sixteen times.
A combinational logic circuit with two inputs (A, B) and two outputs (Sum, Carry), designed to add two single-bit binary numbers.
Adders are the basic building blocks of the ALU. In the half adder the sum output is 1 whenever an odd number of inputs are 1 — exactly the XOR behaviour — and the carry is 1 only when both inputs are 1, which is the AND behaviour.
| A | B | S (sum) | C (carry) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
Limitation: the half adder has no carry-in input, so the carry of a previous addition cannot be included. It therefore cannot be chained to add multi-bit numbers — that job needs the full adder.
A ⊕ B (XOR) — option (c).
Developed to overcome the drawback of the half adder: it adds three one-bit inputs — A, B and the carry-in Cin — and produces Sum and Carry-out.
| A | B | Cin | S | Cout |
|---|---|---|---|---|
| 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 |
A full adder equals two half adders + one OR gate: the first HA adds A and B, the second HA adds that sum to Cin, and the OR merges the two partial carries. Its delay is about two gate levels, and cascading n full adders gives the n-bit ripple carry adder.
Write it in this order: (1) definition (3 inputs A, B, Cin; 2 outputs S, Cout) → (2) truth table (8 rows) → (3) Boolean expressions → (4) gate diagram → (5) note that two HAs + OR make one FA. Everything above is the answer.
The subtraction counterpart of the full adder: computes A − B − Bin producing Difference D and Borrow-out Bout.
The difference bit has exactly the same pattern as the full-adder sum — XOR of all three inputs. The borrow is 1 when B is larger than what is available: either A is 0 and B is 1, or the incoming borrow arrives while A ⊕ B is 0 (both bits equal).
| A | B | Bin | D | Bout |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 |
Exam shortcut: D of a full subtractor = S of a full adder. Only the borrow equation differs from the carry equation. With the XOR-plus-mode-line trick (next but one section) the same adder hardware performs subtraction, which is why real ALUs do not keep separate subtractor circuits.
Definition → truth table → expressions D and Bout → diagram, exactly mirroring the full-adder answer. Mention that the borrow logic treats “A < B” cases.
An n-bit adder made by cascading n full adders — the carry of each stage “ripples” into the next stage, so addition becomes a serial process.
Carry ripple example (4-bit):
Cout A₃B₃ A₂B₂ A₁B₁ A₀B₀
1 1 0 1 1 A = 1011 (11)
1 1 0 1 B = 1101 (13)
--------------------------
1 1 0 0 0 0 Sum = 11000 (24)Definition → how carry ripples (points above) → 4-bit cascade diagram → the 1011 + 1101 worked example → delay discussion.
Limitations: (1) each full adder must wait for its carry-in from the previous stage → large propagation time; (2) delay increases with the number of bits, so RCAs are extremely slow when adding many bits; (3) the worst-case path is the carry chain itself. Suitable replacement: the Carry Look-ahead Adder — it generates every carry simultaneously from P/G signals in a constant number of gate delays (slightly costlier hardware).
An improved, fast parallel adder that solves the carry-propagation problem by calculating every carry in advance, directly from the input bits.
In every bit position two internal signals are defined from the operands alone — they settle after a single gate delay:
Expanding Ci+1 = Gi + PiCi repeatedly expresses every carry in terms of the inputs only — so all of them are produced in parallel:
Speed: P values are valid one XOR-gate delay and G values one AND-gate delay after the operands. Every carry Ci+1 is then ready in 3 gate delays and every sum Si in 4 gate delays — independent of n, against ≈ 2n gate delays (10 ns per FA → 40 ns) for the ripple adder.
Worked example (learn this — it answers “with suitable example”):
| bit i | Ai Bi | Pi | Gi | Ci | Si |
|---|---|---|---|---|---|
| 0 | 1 0 | 1 | 0 | C₀ = 0 | 1 |
| 1 | 1 1 | 0 | 1 | C₁ = 0 | 0 |
| 2 | 0 1 | 1 | 0 | C₂ = 1 | 0 |
| 3 | 1 0 | 1 | 0 | C₃ = 1 | 0 |
A = 1011 (11), B = 0110 (6), C₀ = 0 → carries C₁C₂C₃C₄ = 0 1 1 1, sum = 1 0001 (17) ✓. Check: C₂ = G₁ + P₁C₁ = 1; C₃ = G₂ + P₂C₂ = 0 + 1·1 = 1; C₄ = G₃ + P₃C₃ = 0 + 1·1 = 1.
• fast look-ahead carry circuits reduce propagation delay (option b). • carry-look-ahead logic uses the concept of generating and propagating carries (option c).
Write: definition → Pi, Gi equations → expanded C₁…C₄ → block/gate diagram (above) → delay comparison table → the 1011 + 0110 example → closing line: CLA carries come in 3–4 gate delays regardless of n, the ripple adder needs ≈ 2n levels (40 ns for 4 bits); cost is extra AND-OR hardware that grows complicated as bits increase.
One circuit that performs both addition and subtraction, switched by a mode control signal M.
Each of B's bits passes through an XOR gate whose other input is M. The XOR truth table makes it work: one input 0 → output equals the second input; one input 1 → output is the complement of the second input.
Design: 8 full adders in cascade, an XOR gate on every B input, all XOR second inputs tied to M, and C₀ = M. The final carry-out C₈ is ignored in subtraction mode.
Addition (M = 0):
A = 78 = 0100 1110
B = 12 = 0000 1100
----------------------
S = 0101 1010 = 90 (C₈ = 0)
Subtraction (M = 1): B is XORed with 1, C₀ = 1
B ⊕ M = 1111 0011 (1's complement of 12)
A + B′ + C₀ = 0100 1110 + 1111 0011 + 1
= 1 0100 0010 → C₈ = 1 (discarded)
Result = 0100 0010 = 66 ✓ (78 − 12)A very powerful tool of digital design used to solve and transform Boolean expressions: the complement of a product equals the sum of the complements, and the complement of a sum equals the product of the complements.
Verification of Theorem 1 (LHS and RHS agree in every row):
| A | B | A·B | (A·B)′ | A′ | B′ | A′+B′ |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 0 | 0 | 0 |
Verification of Theorem 2:
| A | B | A+B | (A+B)′ | A′ | B′ | A′·B′ |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 | 1 | 1 |
| 0 | 1 | 1 | 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 | 0 | 0 | 0 |
Applications: with De Morgan's laws any Boolean expression can be built using only NAND or only NOR gates — one universal gate type for the whole circuit, which makes hardware design cheaper. The laws are also used in verifying SAS code, across computer and electrical engineering, and in Java programming.
The usual long multiplication we do in decimal applies to binary too: multiplying two n-bit numbers gives a 2n-bit product.
B₃B₂B₁B₀
1 1 0 1 13
× 1 1 0 6
─────────────────
0 0 0 0 ← A₀ partial product (×1)
1 1 0 1 ← A₁ partial product (×2, shifted)
1 1 0 1 ← A₂ partial product (×4, shifted)
─────────────────
1 0 0 1 1 1 0 = 78 ✓
• the standard method used for binary multiplication (of signed numbers) is Booth's Algorithm (option b). • in 110 × 1000 the operands are treated as n-bit quantities — 110 is padded to 0110, so n = 4 (option c).
Hardware version of paper-and-pencil multiplication: n cycles of “add the multiplicand if the multiplier bit is 1, then shift right”.
| Cycle | C | A | Q | B | Operation |
|---|---|---|---|---|---|
| 0 | 0 | 0000 | 0100 | 1100 | Initialise (B = multiplicand, Q = multiplier) |
| 0 | 0000 | 0100 | 1100 | Q0 = 0 → No add | |
| 0 | 0000 | 0010 | 1100 | Shift right C,A,Q | |
| 0 | 0000 | 0010 | 1100 | Q0 = 0 → No add | |
| 0 | 0000 | 0001 | 1100 | Shift right C,A,Q | |
| 3 | 0 | 1100 | 0001 | 1100 | Q0 = 1 → Add B to A |
| 0 | 0110 | 0000 | 1100 | Shift right C,A,Q | |
| 0 | 0110 | 0000 | 1100 | Q0 = 0 → No add | |
| 0 | 0011 | 0000 | 1100 | Shift right C,A,Q | |
| Product = A · Q = 00110000 | = 48 ✓ | ||||
B = 1100 (12), Q = 0100 (4) → product 0011 0000 = 48. Only one addition happens (when Q₀ = 1 in cycle 3) — the two shifts before it pull that 1 up to Q₀.
| Cycle | C | A | Q | B | Operation |
|---|---|---|---|---|---|
| 0 | 0 | 0000 | 1001 | 1010 | Initialise (B = multiplicand, Q = multiplier) |
| 1 | 0 | 1010 | 1001 | 1010 | Q0 = 1 → Add B to A |
| 0 | 0101 | 0100 | 1010 | Shift right C,A,Q | |
| 0 | 0101 | 0100 | 1010 | Q0 = 0 → No add | |
| 0 | 0010 | 1010 | 1010 | Shift right C,A,Q | |
| 0 | 0010 | 1010 | 1010 | Q0 = 0 → No add | |
| 0 | 0001 | 0101 | 1010 | Shift right C,A,Q | |
| 4 | 0 | 1011 | 0101 | 1010 | Q0 = 1 → Add B to A |
| 0 | 0101 | 1010 | 1010 | Shift right C,A,Q | |
| Product = A · Q = 01011010 | = 90 ✓ | ||||
B = 1010 (10), Q = 1001 (9) → product 0101 1010 = 90.
| Cycle | C | A | Q | B | Operation |
|---|---|---|---|---|---|
| 0 | 0 | 0000 | 1011 | 1101 | Initialise (B = multiplicand, Q = multiplier) |
| 1 | 0 | 1101 | 1011 | 1101 | Q0 = 1 → Add B to A |
| 0 | 0110 | 1101 | 1101 | Shift right C,A,Q | |
| 2 | 1 | 0011 | 1101 | 1101 | Q0 = 1 → Add B to A |
| 0 | 1001 | 1110 | 1101 | Shift right C,A,Q | |
| 0 | 1001 | 1110 | 1101 | Q0 = 0 → No add | |
| 0 | 0100 | 1111 | 1101 | Shift right C,A,Q | |
| 4 | 1 | 0001 | 1111 | 1101 | Q0 = 1 → Add B to A |
| 0 | 1000 | 1111 | 1101 | Shift right C,A,Q | |
| Product = A · Q = 10001111 | = 143 ✓ | ||||
B = 1101 (13), Q = 1011 (11) → product 1000 1111 = 143; at the end both A and Q hold the result.
A powerful algorithm for signed (two's-complement) multiplication: it treats positive and negative operands uniformly and generates a 2n-bit product.
Idea: represent the multiplier as a difference of two numbers so the number of additions shrinks — e.g. 30 = 11110₂ = +32 − 2 → recoded +1 0 0 0 −1 0: add M once, subtract M once instead of adding four times. More examples: 200 = 011001000₂ → +1 0 −1 0 +1 −1 0 0 (= 256 − 32 + 8 − 4).
Efficiency: Booth reduces additions for “good” multipliers — alternating patterns need 4 additions against 8 for plain shift-and-add; ordinary patterns 7 vs 9. But it can make it worse: for isolated 1s the recoded multiplier is all ±1s and Booth takes 16 operations against 8. On average there is no big speed gain — the real win is uniform handling of negative numbers.
M = 1011 = −5 (multiplicand), Q = 0011 = +3 (multiplier), n = 4, A = 0000, Q₋₁ = 0:
| Cycle | Q₀ Q₋₁ | Operation | A after op | A | Q | Q₋₁ |
|---|---|---|---|---|---|---|
| — | — | Initialise | — | 0000 | 0011 | 0 |
| 1 | 10 | A ← A − M | 0101 | 0010 | 1001 | 1 |
| 2 | 11 | no add / sub | 0010 | 0001 | 0100 | 1 |
| 3 | 01 | A ← A + M | 1100 | 1110 | 0010 | 0 |
| 4 | 00 | no add / sub | 1110 | 1111 | 0001 | 0 |
| After n cycles → product = A · Q = 11110001 | = -15 ✓ | |||||
1111 0001 in 8-bit two's complement = −15 ✓ (−5 × 3).
M = 1001 = −7, Q = 0110 = +6, n = 4:
| Cycle | Q₀ Q₋₁ | Operation | A after op | A | Q | Q₋₁ |
|---|---|---|---|---|---|---|
| — | — | Initialise | — | 0000 | 0110 | 0 |
| 1 | 00 | no add / sub | 0000 | 0000 | 0011 | 0 |
| 2 | 10 | A ← A − M | 0111 | 0011 | 1001 | 1 |
| 3 | 11 | no add / sub | 0011 | 0001 | 1100 | 1 |
| 4 | 01 | A ← A + M | 1010 | 1101 | 0110 | 0 |
| After n cycles → product = A · Q = 11010110 | = -42 ✓ | |||||
1101 0110 = −42 ✓. (Check: 11010110 = −128+64+16+4+2 = −42.)
• binary multiplication → Booth's Algorithm. • a machine-language instruction format consists of operation code field & operand field. • in 19 × 4 the 4 is the multiplier. • Booth's algorithm is applied on binary (two's-complement) numbers.
Derived directly from Booth: group the Booth-recoded multiplier bits in pairs — this halves the maximum number of summands to n/2.
Key observation: the pair (+1, −1) equals (0, +1) — instead of subtracting M at position i and adding M at i+1, just add M at position i. In the same way (+1, 0) ≡ (0, +2) and (−1, +1) ≡ (0, −1). Each pair (bi+1 bi) together with the bit to its right bi−1 maps to one summand:
| bᵢ₊₁ | bᵢ | bᵢ₋₁ | Recoded | Summand |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | — |
| 0 | 0 | 1 | +1 | +M |
| 0 | 1 | 0 | +1 | +M |
| 0 | 1 | 1 | +2 | +2M |
| 1 | 0 | 0 | −2 | −2M |
| 1 | 0 | 1 | −1 | −M |
| 1 | 1 | 0 | −1 | −M |
| 1 | 1 | 1 | 0 | — |
Why faster: bit-pair recoding reduces the summands by a factor of 2 compared with plain multiplication, each summand still costs one add, and the final product can be produced with a carry-look-ahead adder. Combined with carry-save addition (next section) this is the standard “fast multiplication” recipe.
Multiplier 27 = 00011011 → bit-pair recoding:
| Pair (bᵢ₊₁ bᵢ , bᵢ₋₁) | Position i | Value |
|---|---|---|
| 1 1 , 0 | 0 | -1 |
| 1 0 , 1 | 2 | -1 |
| 0 1 , 1 | 4 | +2 |
| 0 0 , 0 | 6 | +0 |
| 0 0 , 0 | 8 | +0 |
Summands (multiplicand M = -11; negative summands written in 2's complement, 12 bits):
| Recoded term | Summand (12 bits) | Decimal | Running sum |
|---|---|---|---|
| -1 × M × 20 | 000000001011 | +11 | 000000001011 |
| -1 × M × 22 | 000000101100 | +44 | 000000110111 |
| +2 × M × 24 | 111010100000 | -352 | 111011010111 |
| Product = 111011010111 | = -297 ✓ | ||
Multiplier -15 = 11110001 → bit-pair recoding:
| Pair (bᵢ₊₁ bᵢ , bᵢ₋₁) | Position i | Value |
|---|---|---|
| 0 1 , 0 | 0 | +1 |
| 0 0 , 0 | 2 | +0 |
| 1 1 , 0 | 4 | -1 |
| 1 1 , 1 | 6 | +0 |
| 1 1 , 1 | 8 | +0 |
Summands (multiplicand M = 12; negative summands written in 2's complement, 11 bits):
| Recoded term | Summand (11 bits) | Decimal | Running sum |
|---|---|---|---|
| +1 × M × 20 | 00000001100 | +12 | 00000001100 |
| -1 × M × 24 | 11101000000 | -192 | 11101001100 |
| Product = 11101001100 | = -180 ✓ | ||
Multiplier 21 = 00010101 → bit-pair recoding:
| Pair (bᵢ₊₁ bᵢ , bᵢ₋₁) | Position i | Value |
|---|---|---|
| 0 1 , 0 | 0 | +1 |
| 0 1 , 0 | 2 | +1 |
| 0 1 , 0 | 4 | +1 |
| 0 0 , 0 | 6 | +0 |
| 0 0 , 0 | 8 | +0 |
Summands (multiplicand M = -13; negative summands written in 2's complement, 12 bits):
| Recoded term | Summand (12 bits) | Decimal | Running sum |
|---|---|---|---|
| +1 × M × 20 | 111111110011 | -13 | 111111110011 |
| +1 × M × 22 | 111111001100 | -52 | 111110111111 |
| +1 × M × 24 | 111100110000 | -208 | 111011101111 |
| Product = 111011101111 | = -273 ✓ | ||
Multiplier -11 = 11110101 → bit-pair recoding:
| Pair (bᵢ₊₁ bᵢ , bᵢ₋₁) | Position i | Value |
|---|---|---|
| 0 1 , 0 | 0 | +1 |
| 0 1 , 0 | 2 | +1 |
| 1 1 , 0 | 4 | -1 |
| 1 1 , 1 | 6 | +0 |
| 1 1 , 1 | 8 | +0 |
Summands (multiplicand M = 15; negative summands written in 2's complement, 11 bits):
| Recoded term | Summand (11 bits) | Decimal | Running sum |
|---|---|---|---|
| +1 × M × 20 | 00000001111 | +15 | 00000001111 |
| +1 × M × 22 | 00000111100 | +60 | 00001001011 |
| -1 × M × 24 | 11100010000 | -240 | 11101011011 |
| Product = 11101011011 | = -165 ✓ | ||
Booth recap → the (+1,−1) ≡ (0,+1) observation → the full bit-pair table → the 27 example above → efficiency: ≤ n/2 summands (Booth/plain: up to n), fewer additions, works with carry-save addition for further speed-up.
A carry-save adder (CSA) — also called a 3-2 adder — adds three binary numbers to two numbers in one full-adder delay, without propagating any carry.
Worked example — summands of 1101 × 1011 (13 × 11 = 143):
| Summand | Binary (8 bits) |
|---|---|
| A (×1) | 0000 1101 |
| B (×2) | 0001 1010 |
| C (×4) | 0000 0000 |
| D (×8) | 0110 1000 |
| Level | Inputs | S vector | C vector |
|---|---|---|---|
| CSA₁ | A, B, C | 0001 0111 | 0001 0000 |
| CSA₂ | S₁, C₁, D | 0110 1111 | 0010 0000 |
| CPA | S₂ + C₂ | 1000 1111 = 143 ✓ | |
Compare: in the ripple-carry array each row of adders must wait for the carry of the row above it; in the carry-save array every row costs one FA delay and the carries are saved for the final adder — a big speed-up when adding many summands.
Definition (3-2 adder, no carry propagation) → S and C vector idea → the 1101 × 1011 worked example → tree diagram → closing: final add with CLA.
Integer division based on longhand division: shift the partial remainder left, subtract the divisor, and if the result went negative, restore it by adding the divisor back.
| Cycle | A after SHL | Q (q₀ slot) | A − M | Action | A | Q |
|---|---|---|---|---|---|---|
| 0 | 0000 | 1010 | — | Initialise (M = 0100) | 0000 | 1010 |
| 1 | 0001 | 0100 | 1101 | A < 0 → q₀ = 0, restore A | 0001 | 0100 |
| 2 | 0010 | 1000 | 1110 | A < 0 → q₀ = 0, restore A | 0010 | 1000 |
| 3 | 0101 | 0000 | 0001 | A ≥ 0 → q₀ = 1 | 0001 | 0001 |
| 4 | 0010 | 0010 | 1110 | A < 0 → q₀ = 0, restore A | 0010 | 0010 |
| Quotient = Q = 0010 (2), Remainder = A = 0010 (2) ✓ | ||||||
| Cycle | A after SHL | Q (q₀ slot) | A − M | Action | A | Q |
|---|---|---|---|---|---|---|
| 0 | 0000 | 1011 | — | Initialise (M = 0101) | 0000 | 1011 |
| 1 | 0001 | 0110 | 1100 | A < 0 → q₀ = 0, restore A | 0001 | 0110 |
| 2 | 0010 | 1100 | 1101 | A < 0 → q₀ = 0, restore A | 0010 | 1100 |
| 3 | 0101 | 1000 | 0000 | A ≥ 0 → q₀ = 1 | 0000 | 1001 |
| 4 | 0001 | 0010 | 1100 | A < 0 → q₀ = 0, restore A | 0001 | 0010 |
| Quotient = Q = 0010 (2), Remainder = A = 0001 (1) ✓ | ||||||
Restoring: after every subtraction the negative result is undone (A + M), so a cycle can need two operations; q₀ = 1 only when A − M ≥ 0. Non-restoring: never restores, next cycle adds instead — see the next section for the other half of the comparison.
Improves restoring division by never adding the divisor back: if A goes negative, the next cycle simply adds M instead of subtracting — one operation per cycle.
| Cycle | A after SHL | Sign? | Operation | A after op | q₀ | Q |
|---|---|---|---|---|---|---|
| 0 | 0000 | — | Initialise (M = 0010, M′ = 2's compl.) | 0000 | — | 1000 |
| 1 | 0001 | A ≥ 0 | A ≥ 0 ← A = A − M | 1111 | 0 | 0000 |
| 2 | 1110 | A ≥ 0 | A < 0 ← A = A + M | 0000 | 0 | 0001 |
| 3 | 0000 | A ≥ 0 | A ≥ 0 ← A = A − M | 1110 | 0 | 0010 |
| 4 | 1100 | A ≥ 0 | A < 0 ← A = A + M | 1110 | 0 | 0100 |
| final A < 0 → correction A ← A + M | Quotient = 0100 (4), Remainder = 0000 (0) ✓ | |||||
| Cycle | A after SHL | Sign? | Operation | A after op | q₀ | Q |
|---|---|---|---|---|---|---|
| 0 | 0000 | — | Initialise (M = 0011, M′ = 2's compl.) | 0000 | — | 1000 |
| 1 | 0001 | A ≥ 0 | A ≥ 0 ← A = A − M | 1110 | 0 | 0000 |
| 2 | 1100 | A ≥ 0 | A < 0 ← A = A + M | 1111 | 0 | 0000 |
| 3 | 1110 | A ≥ 0 | A < 0 ← A = A + M | 0001 | 0 | 0001 |
| 4 | 0010 | A ≥ 0 | A ≥ 0 ← A = A − M | 1111 | 0 | 0010 |
| final A < 0 → correction A ← A + M | Quotient = 0010 (2), Remainder = 0010 (2) ✓ | |||||
Here the final A is negative, so the correction A ← A + M is applied before reading the remainder.
| Restoring | Non-restoring | |
|---|---|---|
| After negative subtraction | Adds M back (restore) | Keeps it; next cycle adds M |
| Operations per cycle | Up to 2 (subtract + restore) | Exactly 1 (add or subtract) |
| Quotient bit rule | q₀ = 1 iff A − M ≥ 0 | q₀ = 1 iff A ≥ 0 after the op |
| End correction | Not needed | A ← A + M if final A < 0 |
| Speed | Slower | Faster (fewer adds) |
| Complexity | Simpler control | Slightly trickier control |
The IEEE Standard for Floating-Point Arithmetic (established 1985) is the common representation of real numbers on computers — Intel PCs, Macs, most Unix platforms.
Three basic components:
Worked example — represent 85.125:
85.125 = 1010101.001₂ = 1.010101001 × 2⁶
Single precision: biased exponent = 127 + 6 = 133 = 1000 0101
mantissa = 0101 0100 1 + zeros → 23 bits
IEEE 754 single = 0 | 10000101 | 01010100100000000000000
= 42AA 4000 (hex)
Double precision: biased exponent = 1023 + 6 = 1029 = 100 0000 0101
IEEE 754 double = 0 | 10000000101 | 010101001 + zeros → 52 bits
= 4055 4800 0000 0000 (hex)Special (reserved) values:
| Exponent | Mantissa | Meaning |
|---|---|---|
| all 0 | 0 | Zero (±0 — distinct bit patterns, both compare equal) |
| all 0 | ≠ 0 | Denormalised number — no assumed leading 1 |
| all 1 | 0 | Infinity — sign bit picks +∞ or −∞ |
| all 1 | ≠ 0 | NaN (Not a Number) — an error / undefined value |
Ranges: five zones a single-precision number cannot represent — negative overflow (below −(2 − 2⁻²³) × 2¹²⁷), negative underflow (between −2⁻¹⁴⁹ and 0), zero, positive underflow (below 2⁻¹⁴⁹), positive overflow (above (2 − 2⁻²³) × 2¹²⁷). Overflow means the value grew too large to represent (serious); underflow is only a loss of precision, closely approximated by zero (less serious). The effective range is symmetric around zero: single ≈ ±1038.53, double ≈ ±10308.25.