1.5 Fixed/Floating Arithmetic & Representations
Data processing requires representing numbers accurately in finite computer memory. This chapter provides a rigorous examination of fixed-point integer systems (sign-magnitude, 1's complement, and 2's complement), details the IEEE 754 floating-point standard, traces Booth's signed multiplication algorithm using full execution tables, and analyzes floating-point arithmetic alignment pipelines.
Learning Objectives
- Define the representation formats for signed integers (sign-magnitude, 1's complement, 2's complement) and IEEE 754 floating-point single and double precision formats.
- Explain the mathematical purpose of biased exponents and the hidden significand bit in floating-point representations.
- Trace the execution steps of Booth's binary multiplication algorithm for signed integers using step-by-step trace tables.
- Contrast fixed-point integer arithmetic with the steps required for floating-point arithmetic (alignment, normalization, rounding).
- Evaluate arithmetic outcomes to identify overflow, underflow, NaN, and subnormal states under the IEEE 754 standard.
Before studying this chapter, you should review Chapter 1.1: General Concepts & Abstraction Levels to understand CPU data pathways and basic arithmetic operations.
1. Fixed-Point Representation
In fixed-point representation, the binary point is assumed to be at a fixed location (typically at the extreme right for integers). Computer hardware uses three standard systems to represent signed integers inside a word of width $N$ bits:
- Sign-Magnitude: The most significant bit (MSB, bit $N-1$) represents the sign ($0$ for positive, $1$ for negative). The remaining $N-1$ bits hold the absolute value.
- Range: $-(2^{N-1}-1)$ to $+(2^{N-1}-1)$.
- Drawback: It has two representations for zero ($+0 = 00000000$ and $-0 = 10000000$), complicating ALU comparison circuits.
- 1's Complement: Positive numbers are identical to sign-magnitude. A negative number is formed by toggling every bit of its positive equivalent (bitwise NOT).
- Range: $-(2^{N-1}-1)$ to $+(2^{N-1}-1)$.
- Drawback: Still contains a dual representation for zero ($+0 = 00000000$ and $-0 = 11111111$).
- 2's Complement: The standard integer representation in modern CPUs. Positive numbers are unchanged. A negative number is formed by taking the 1's complement of its positive equivalent and adding $1$.
- Range: $-2^{N-1}$ to $+(2^{N-1}-1)$.
- Advantage: Only a single representation of zero ($00000000$). Addition and subtraction are executed using identical hardware.
1.1 Two's Complement Arithmetic and Overflow Detection
To subtract two numbers in 2's complement ($A - B$), the ALU negates the subtrahend $B$ (forming its 2's complement $-B$) and adds it to $A$: $$A - B = A + (-B)$$ During addition, an **overflow** occurs if the result of adding two $N$-bit numbers exceeds the range of the representation.
Hardware Overflow Rule: An overflow occurs if and only if the carry-in ($C_{in}$) into the sign bit (MSB) does not equal the carry-out ($C_{out}$) of the sign bit: $$\text{Overflow} = C_{in} \oplus C_{out}$$ Alternatively, adding two positive numbers that yields a negative result, or adding two negative numbers that yields a positive result, indicates overflow.
2. Floating-Point Representation (IEEE 754)
To represent very large integers or small fractions, computers use scientific notation adapted for binary. The IEEE 754 standard defines how floating-point numbers are stored:
Where:
- $S$ is the Sign Bit (1 bit, 0 = positive, 1 = negative).
- $F$ is the Fractional Significand (Mantissa), stored with an implicit, unstored **hidden bit** of value 1 preceding the binary point ($1.F$).
- $E$ is the biased Exponent. An offset (**Bias**) is added to the actual exponent to ensure the exponent field is always stored as an unsigned positive integer.
2.1 Format Layout Specifications
- Single-Precision (32-bit): 1-bit sign, 8-bit exponent (Bias = $127$), 23-bit mantissa. Stored exponent range: $1 \le E \le 254$ (actual exponents: $-126$ to $+127$).
- Double-Precision (64-bit): 1-bit sign, 11-bit exponent (Bias = $1023$), 52-bit mantissa. Stored exponent range: $1 \le E \le 2046$ (actual exponents: $-1022$ to $+1023$).
┌───┬───────────────┬───────────────────────────────────────────┐
│ S │ Exponent (E) │ Fraction (F) │
└───┴───────────────┴───────────────────────────────────────────┘
Bit: 31 30 - 23 22 - 0
(1 bit) (8 bits) (23 bits)
2.2 Special Values Matrix
- Zero: $E = 0, F = 0$ (both $+0$ and $-0$ exist depending on $S$).
- Denormalized (Subnormal) Numbers: $E = 0, F \ne 0$. Used to represent numbers close to zero; the hidden bit becomes $0$ ($0.F$).
- Infinity ($\pm\infty$): $E = 255$ (single) or $E = 2047$ (double), $F = 0$.
- NaN (Not a Number): $E = 255$ (single) or $E = 2047$ (double), $F \ne 0$. Used to signal invalid operations (e.g., $0/0$ or $\sqrt{-1}$).
3. Integer Arithmetic: Booth's Multiplication Algorithm
Booth's algorithm is a hardware multiplication technique that treats signed 2's complement integers directly. It speeds up multiplication by replacing consecutive additions with subtraction at the start of a run of 1s and addition at the end of the run.
Let $M$ be the Multiplicand, $Q$ the Multiplier, and $A$ a running register initialized to zero. An extra single-bit flip-flop $Q_{-1}$ is placed to the right of the LSB of $Q$ and initialized to $0$. In each of the $N$ steps:
- Examine the two bits $Q_0$ (LSB of $Q$) and $Q_{-1}$:
- **$00$ or $11$**: Do nothing.
- **$10$**: Subtract multiplicand $M$ from register $A$ ($A \leftarrow A - M$).
- **$01$**: Add multiplicand $M$ to register $A$ ($A \leftarrow A + M$).
- Perform an **Arithmetic Right Shift (ARS)** of the combined registers $[A, Q, Q_{-1}]$ by 1 bit. ARS preserves the sign of $A$ (the MSB of $A$ is shifted into itself).
- Repeat $N$ times (where $N$ is the word size in bits). The final product is held in the concatenated registers $[A, Q]$.
4. Floating-Point Arithmetic Operations
Floating-point addition and subtraction require aligning exponents before the mantissas can be combined:
- Exponent Comparison: Extract the exponents $E_1$ and $E_2$. Calculate the difference $d = |E_1 - E_2|$.
- Significand Alignment: Shift the significand of the number with the smaller exponent to the right by $d$ bits. Set the exponent of the result to the larger exponent.
- Significand Addition/Subtraction: Add or subtract the aligned significands based on the signs of the operands.
- Normalization: Shift the resulting significand left or right so it starts with a leading $1$ (e.g. $1.F$), and increment or decrement the exponent accordingly.
- Rounding: Round the significand to fit the target precision (using Guard, Round, and Sticky bits). If rounding causes an overflow in the significand, shift right again and increment the exponent.
5. Comprehensive Solved Examples
Two's Complement Subtraction & Overflow Trace
Problem: Using 8-bit signed 2's complement representation, perform the subtraction $A - B$ for $A = 75$ and $B = -60$. State if an overflow occurs, verifying with the XOR carry rule.
Solution:
- Represent $A = +75$ in binary: $$75 = 64 + 8 + 2 + 1 \Rightarrow A = 01001011_2$$
- Represent $B = -60$ in binary: - Positive $60 = 32 + 16 + 8 + 4 = 00111100_2$. - 1's complement = $11000011_2$. - 2's complement ($B$) = $11000011_2 + 1 = 11000100_2$.
- Determine $-B$ (negating $-60$ back to $+60$): $$-B = 00111100_2$$
- Perform addition $A + (-B)$:
Carries: 0 1 0 0 1 1 1 1 0 A (75): 0 1 0 0 1 0 1 1 -B (60): + 0 0 1 1 1 1 0 0 ────────────────────────── Sum: 1 0 0 0 0 1 1 1 - Evaluate Carries & Overflow: - Carry into the sign bit ($C_{in}$) = $1$ (carried from column 6 to column 7). - Carry out of the sign bit ($C_{out}$) = $0$. - $\text{Overflow} = C_{in} \oplus C_{out} = 1 \oplus 0 = 1$ (Overflow detected!). - *Check*: $A + (-B) = 75 + 60 = 135$. The maximum positive value an 8-bit signed integer can hold is $+127$. Thus, $135$ overflows, wrapping around to a negative representation: $10000111_2 = -121$.
Answer: $A - B = 10000111_2$. An **overflow occurs** since the actual sum $135$ exceeds $+127$.
Decimal to Single-Precision IEEE-754 Hex
Problem: Encode the decimal number $-12.625$ into the standard 32-bit single-precision IEEE 754 format. Show the hex representation.
Solution:
- Determine the Sign Bit ($S$): Since the number is negative, **$S = 1$**.
- Convert the absolute value $12.625$ to binary: - Integer part: $12 = 8 + 4 = 1100_2$. - Fractional part: $0.625 = 0.5 + 0.125 = 2^{-1} + 2^{-3} = .101_2$. - Combined binary: $12.625 = 1100.101_2$.
- Normalize the binary number: Shift the binary point 3 places to the left to obtain a leading 1: $$1100.101_2 = 1.100101_2 \times 2^3$$ - The actual exponent is **$3$**. - The fractional significand (Mantissa $F$) is **$100101$** (which becomes $10010100000000000000000_2$ when padded to 23 bits).
- Calculate the Biased Exponent ($E$): $$\text{Bias} = 127$$ $$E = \text{Actual Exponent} + \text{Bias} = 3 + 127 = 130_{10}$$ Convert $130$ to 8-bit binary: $$130 = 128 + 2 \Rightarrow E = 10000010_2$$
- Assemble the 32-bit word:
S | Exponent | Mantissa ──┼──────────────┼────────────────────────────────────────── 1 | 1 0 0 0 0 0 1 | 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Regrouping into 4-bit nibbles: 1100 0001 0100 1010 0000 0000 0000 0000 C 1 4 A 0 0 0 0
Answer: The IEEE 754 single-precision hex representation of $-12.625$ is **`0xC14A0000`**.
IEEE-754 Hex back to Decimal
Problem: Decode the 32-bit single-precision IEEE 754 word stored as **`0x41C40000`** back into its decimal equivalent.
Solution:
- Convert hex to binary: $$41\text{C}40000 \Rightarrow 0100\ 0001\ 1100\ 0100\ 0000\ 0000\ 0000\ 0000_2$$
- Extract the fields: - **Sign Bit ($S$)**: Bit 31 is **`0`** (positive). - **Exponent ($E$)**: Bits 30–23 are **`10000011`** ($131_{10}$). - **Mantissa ($F$)**: Bits 22–0 are **`10001000000000000000000`**.
- Calculate the Actual Exponent: $$\text{Actual Exponent} = E - 127 = 131 - 127 = 4$$
- Determine the Significand value ($1.F$): Recall the implicit hidden bit of value 1: $$\text{Significand} = 1 + F = 1.10001_2$$ Convert fractional binary to base-10: $$1.10001_2 = 1 + 2^{-1} + 2^{-5} = 1 + 0.5 + 0.03125 = 1.53125_{10}$$
- Reconstruct value: $$V = +1.10001_2 \times 2^4 = 11000.1_2$$ $$11000.1_2 = 16 + 8 + 2^{-1} = 24 + 0.5 = 24.5$$
Answer: The decoded decimal value is **`+24.5`**.
Booth's Multiplication Trace Table
Problem: Trace the execution of Booth's algorithm for $M = -7$ (Multiplicand) and $Q = 5$ (Multiplier) using 5-bit registers. State the final product.
Solution:
- Represent operands in 5-bit 2's complement: - Positive $7 = 00111_2 \Rightarrow -7 = 11000_2 + 1 = 11001_2$. So $M = 11001$, and $-M = 00111$. - Multiplier $Q = 5 = 00101_2$.
- Initialize registers: $A = 00000$, $Q = 00101$, $Q_{-1} = 0$, step count $N = 5$.
- Step-by-step Trace Table:
| Step | Operation | Register A | Register Q | Q_0 Q_-1 | Count (N) |
|---|---|---|---|---|---|
| 0 | Initialization | 00000 | 00101 | 1 0 | 5 |
| 1 | A ← A - M (Add 00111) ARS |
00111 00011 |
00101 10010 |
0 1 | 4 |
| 2 | A ← A + M (Add 11001) ARS |
11100 11110 |
10010 01001 |
1 0 | 3 |
| 3 | A ← A - M (Add 00111) ARS |
00101 00010 |
01001 10100 |
0 1 | 2 |
| 4 | A ← A + M (Add 11001) ARS |
11011 11101 |
10100 11010 |
0 0 | 1 |
| 5 | No addition (00) ARS |
11101 11110 |
11010 11101 |
— | 0 |
Verify final concatenation $[A, Q]$:
Result = $11110\ 11101_2$ (10 bits). Since the MSB is $1$, this is a negative number. - 1's complement = $00001\ 00010_2$. - 2's complement = $00001\ 00010_2 + 1 = 00001\ 00011_2 = 32 + 2 + 1 = 35_{10}$. - Since the sign was negative, the result is $-35_{10}$. This matches $-7 \times 5 = -35$.
Answer: The final binary product is **`1111011101`** (representing $-35$).
6. Core Comparison Tables
Table 1.5.3: Fixed-Point Ranges (for 8-bit registers)
| Representation | Minimum Value | Maximum Value | Zero Representation |
|---|---|---|---|
| Sign-Magnitude | $-127$ ($11111111_2$) | $+127$ ($01111111_2$) | Dual ($+0$ and $-0$) |
| 1's Complement | $-127$ ($10000000_2$) | $+127$ ($01111111_2$) | Dual ($+0$ and $-0$) |
| 2's Complement | $-128$ ($10000000_2$) | $+127$ ($01111111_2$) | Unique ($00000000_2$) |
7. Common Mistakes Students Make
Common Pitfalls & Cognitive Traps
- Applying Logical Right Shift during Booth's Traces: In Booth's algorithm, the shift operation must be an **Arithmetic Right Shift (ARS)**. A logical shift inserts $0$ into the MSB, which corrupts the sign of negative numbers. ARS copies the sign bit into itself.
- Omitting the Hidden Bit ($1.F$) in Float Operations: When adding or subtracting IEEE 754 numbers, students frequently align and add the mantissas ($F_1, F_2$) directly. The implicit hidden bit ($1$) must be explicitly re-inserted (yielding $1.F$) before alignment shifts and ALU operations are executed.
- Incorrect Bias Applications: Students sometimes subtract the bias when encoding and add it when decoding. Keep this clear: - *Encoding (Decimal to IEEE)*: Add Bias (Stored $E = \text{Actual} + 127$). - *Decoding (IEEE to Decimal)*: Subtract Bias (Actual Exponent $= E - 127$).
- Incorrect Overflow Checks: Many believe a carry out of the MSB ($C_{out} = 1$) always indicates overflow in 2's complement. This is only true for unsigned math. For signed 2's complement, an overflow is only flagged if $C_{in}$ into the sign bit does not match $C_{out}$ ($C_{in} \ne C_{out}$).
🎯 Key Takeaways
- **2's Complement** is favored by modern processors because it eliminates the dual-zero representation and allows addition/subtraction to use the same hardware.
- The **IEEE 754 single-precision format** is a 32-bit structure containing a Sign bit, an 8-bit biased Exponent, and a 23-bit Mantissa with an implicit hidden bit.
- **Booth's algorithm** provides signed 2's complement integer multiplication without requiring sign correction steps.
- **Floating-point addition** requires a sequential pipeline: compare exponents, shift mantissas for alignment, add, normalize, and round.
🔗 Connection to Future Chapters
The numeric representations and Booth steps learned here serve as the baseline logic for the physical ALU circuit mappings in **Chapter 2.1**.
8. Assessment Bank
8.1 Multiple Choice Questions
Answer: (b). In 8-bit 2's complement, the pattern `10000000` represents the minimum possible value: $-2^{7} = -128$.
Answer: (b). Decimal $0.5 = 1.0 \times 2^{-1}$. The actual exponent is $-1$. The biased exponent is $-1 + 127 = 126$.
Answer: (b). A transition of $10$ represents the start of a block of 1s in the multiplier, requiring a subtraction ($A \leftarrow A - M$) before shifting.
Answer: (c). Overflow $= C_{in} \oplus C_{out}$. If $C_{in} = 1$ and $C_{out} = 0$ (or vice-versa), the XOR result is $1$, asserting overflow.
8.2 Short Answer Questions
- Define the role of the "Hidden Bit" in IEEE 754 and explain why it is not physically stored.
- Write the range of 16-bit signed integers in 2's complement and sign-magnitude.
- Explain why arithmetic right shift (ARS) is used instead of logical right shift (LSR) during Booth's algorithm.
8.3 Long Answer / Exam Questions
- Trace the Booth's multiplication algorithm step-by-step for $M = -9$ (Multiplicand) and $Q = -6$ (Multiplier) using 5-bit signed numbers. Show the trace table including A, Q, and $Q_{-1}$ at each step, and verify the final result.
- Show the complete steps of floating-point addition to calculate the sum of $A = 0.75_{10}$ and $B = 4.25_{10}$ in IEEE 754 single-precision format. Show exponent comparison, mantissa shift alignment, addition, and normalization.
8.4 Viva Voce Questions
- "What is a subnormal number in IEEE 754, and why do modern CPUs experience performance penalties when processing them?" Model Answer: A subnormal (denormalized) number is a floating-point value where the exponent field is all 0s but the mantissa is non-zero. They represent numbers extremely close to zero and use an implicit hidden bit of $0$. Many CPUs cannot process denormalized values in their fast hardware pipelines, forcing them to trap to microcode or software routines, causing a massive performance penalty.
- "Why does 2's complement subtraction not require separate subtraction logic circuits in the ALU?" Model Answer: Because $A - B$ is mathematically equivalent to $A + (-B)$. The ALU can negate the input $B$ using bitwise NOT gates and setting the carry-in ($C_0$) of the adder to $1$, allowing the standard binary adder circuit to perform the subtraction.