Skip to main content

7.3 Binary Arithmetic, Overflow Detection & Floating Point

πŸ“šModule 07: Number Systems, Complements & ArithmeticTopic 7.3⏱️24 min read
🎯High-Yield For:University Semester Exams β€’ Hardware Engineering Rounds β€’ Foundational Computing

πŸ’‘ Core Intuition: The Odometer Rolling Backward & The Floating Decimal Point​

Every microprocessor Arithmetic Logic Unit (ALU) operates under a severe physical constraint: fixed register bit width. Whether an Intel Core i9, an AMD Ryzen, or an Apple M4, hardware registers have hard boundaries (8,16,32,8, 16, 32, or 6464 bits).

When a program performs integer arithmetic, the result can exceed the maximum representable value of the register. This phenomenon is Arithmetic Overflowβ€”the silent killer of embedded software and spacecraft control systems (most famously causing the catastrophic destruction of the Ariane 5 rocket in 1996 when a 64-bit floating-point number overflowed a 16-bit signed integer register).

🍳 The Everyday Analogy: Scientific Notation on a Pocket Calculator​

How can a digital device represent both the mass of the Sun (1.989Γ—1030 kg1.989 \times 10^{30}\,\text{kg}) and the mass of an electron (9.109Γ—10βˆ’31 kg9.109 \times 10^{-31}\,\text{kg}) using the same number of display digits?

If a calculator used a fixed decimal point (like a dollar balance displaying two decimal places: $XXXXXX.YY), representing an electron would require over thirty leading zeros:

0.00000000000000000000000000000091090.0000000000000000000000000000009109

This wastes nearly all available memory on non-informative zeros! Instead, scientific notation "floats" the decimal point so that it always sits directly after the first significant digit, storing only the significant digits (mantissa) and the power of ten (exponent).

The IEEE 754 Standard adapts this exact principle to base-2 binary hardware, granting modern computers an astonishing dynamic range while using just 32 or 64 bits of physical silicon.

πŸ’» Bridging to Computer Science​

Binary arithmetic and floating-point representations form the bedrock of computing systems and compilers:

  1. The ALU Status Register: Microprocessors expose arithmetic flags (EFLAGS in x86, CPSR in ARM) where the Carry Flag (CC) indicates unsigned overflow and the Overflow Flag (VV) flags signed 2's complement overflow. Compilers use these flags to generate branch conditions (jge, jl, ja, jb).
  2. IEEE 754 Floating-Point Units: Modern CPUs, GPUs, and TPUs include dedicated vector FPUs (e.g., AVX-512, ARM NEON) capable of billions of floating-point operations per second (FLOPS). The implicit leading 1 trick gives a free extra bit of precision across all computations.
  3. Spacecraft & Critical Systems Hazards: Software defects caused by numeric overflow or precision loss have led to severe catastrophic failuresβ€”most famously the Ariane 5 rocket explosion in 1996 ($370M loss caused by 64-bit float to 16-bit signed integer conversion overflow) and the Patriot missile radar drift in 1991 (caused by floating-point binary conversion truncation in 24-bit registers).


πŸ”’ Signed Binary Representations & Dynamic Ranges​

To represent negative numbers in hardware, the Most Significant Bit (MSB, bit nβˆ’1n-1) is designated as the Sign Bit:

  • MSB=0β€…β€ŠβŸΉβ€…β€ŠPositiveΒ Number\text{MSB} = \mathbf{0} \implies \text{Positive Number}
  • MSB=1β€…β€ŠβŸΉβ€…β€ŠNegativeΒ Number\text{MSB} = \mathbf{1} \implies \text{Negative Number}

Four competing representations have existed across computing history:

πŸ“Dynamic Range Formulas for n-Bit Systemsformula
  • Unsigned: [0,β€…β€Š2nβˆ’1][0, \; 2^n - 1] (e.g. 8-bit: [0,255][0, 255])
  • Signed-Magnitude: [βˆ’(2nβˆ’1βˆ’1),β€…β€Š+(2nβˆ’1βˆ’1)][-(2^{n-1} - 1), \; +(2^{n-1} - 1)] (e.g. 8-bit: [βˆ’127,+127][-127, +127])
  • 1's Complement: [βˆ’(2nβˆ’1βˆ’1),β€…β€Š+(2nβˆ’1βˆ’1)][-(2^{n-1} - 1), \; +(2^{n-1} - 1)] (e.g. 8-bit: [βˆ’127,+127][-127, +127])
  • 2's Complement: [βˆ’2nβˆ’1,β€…β€Š+(2nβˆ’1βˆ’1)][-2^{n-1}, \; +(2^{n-1} - 1)] (e.g. 8-bit: [βˆ’128,+127][-128, +127])

βš™οΈ The Unified Adder-Subtractor Circuit Architecture​

Because 2's complement subtraction is mathematically equivalent to adding the 2's complement:

Aβˆ’B=A+(βˆ’B)=A+(BΛ‰+1)A - B = A + (-B) = A + (\bar{B} + 1)

An ALU does not require separate adder and subtractor hardware. Instead, it utilizes an nn-bit parallel adder augmented with a bank of XOR gates and a single Mode Control Line (MM):

Architecture Flow

Unified 4-Bit Adder-Subtractor Datapath Pipeline

Controlling dual arithmetic modes (A + B vs A - B) via XOR controlled inverters and Mode bit M

Control Line

Mode Control (M)

M = 0 (Add) | M = 1 (Sub)

Steers XOR inversion and supplies initial carry Cin = M into LSB Full Adder.

β†’
Drives XORs & C0
Conditioning

XOR Controlled Inverters

Bi βŠ• M

When M=0: Bi βŠ• 0 = Bi (buffer). When M=1: Bi βŠ• 1 = Bi' (bitwise 1's complement invert).

β†’
Feeds Full Adders
Arithmetic Core

Parallel Full Adder Array

4 Γ— 1-Bit Full Adders

Computes Ai + (Bi βŠ• M) + Ci. Internal ripple carry propagates C0 β†’ C1 β†’ C2 β†’ C3 β†’ C4.

β†’
Generates Sum & Cout
Outputs

Result Outputs

Sum [S3..S0] & Cout

When M=0: Sum = A + B. When M=1: Sum = A + B' + 1 = A - B (2's complement subtraction).

Adder-Subtractor Dual Operational Modes

How the single Mode line M toggles hardware between addition and subtraction

A + B

Addition Mode (M = 0)

Dominant Architecture / DomainDirect Addition
  • β€’Mode control M = 0 drives XOR gates: Bi βŠ• 0 = Bi (unmodified pass-through).
  • β€’Initial Carry-In C0 = M = 0.
  • β€’Full Adder computes: Sum = A + B + 0 = A + B.
  • β€’Carry flag Cout indicates unsigned arithmetic overflow beyond 4 bits.
A - B

Subtraction Mode (M = 1)

Dominant Architecture / Domain2's Complement Addition
  • β€’Mode control M = 1 drives XOR gates: Bi βŠ• 1 = Bi' (controlled bitwise inversion).
  • β€’Initial Carry-In C0 = M = 1 (supplies the +1 for 2's complement).
  • β€’Full Adder computes: Sum = A + B' + 1 = A - B.
  • β€’End carry Cout = 1 indicates positive result (M β‰₯ B); Cout = 0 indicates negative result.

Operational Modes​

  1. Addition Mode (M=0M = 0):
    • For every bit: BiβŠ•0=BiB_i \oplus 0 = B_i (the BB inputs pass through unmodified).
    • Carry-in to LSB: C0=M=0C_0 = M = 0.
    • Circuit computes: Sum=A+B+0=A+B\text{Sum} = A + B + 0 = \mathbf{A + B}.
  2. Subtraction Mode (M=1M = 1):
    • For every bit: BiβŠ•1=BΛ‰iB_i \oplus 1 = \bar{B}_i (the XOR gates act as controlled inverters, computing the 1's complement).
    • Carry-in to LSB: C0=M=1C_0 = M = 1.
    • Circuit computes: Sum=A+BΛ‰+1=Aβˆ’B\text{Sum} = A + \bar{B} + 1 = \mathbf{A - B}!

This elegant design executes both operations with zero added delay beyond a single XOR propagation gate (tpdβ‰ˆ0.1 nst_{pd} \approx 0.1\,\text{ns}).


🚩 Carry Flag (CC) vs. Overflow Flag (VV): The Silicon Distinction​

One of the most frequent points of confusion in computer systems is the difference between the Carry Flag (CoutC_{out}) and the Overflow Flag (VV) in the CPU Status Register (EFLAGS in x86, CPSR in ARM):

Illustrative 8-Bit Example​

Consider adding 130+130130 + 130 vs. (+70)+(+80)(+70) + (+80):

  • In 8-bit unsigned: 130+130=260130 + 130 = 260. Since 260>255260 > 255, it rolls over to 44 and sets C=1C = 1 (Carry generated).
  • In 8-bit signed: +70+(+80)=+150+70 + (+80) = +150. Since +150>+127+150 > +127, the MSB flips to 11 (yielding βˆ’106-106 in 2's complement). This sets V=1V = 1 (Signed Overflow), even though no unsigned carry was generated (C=0C = 0)!

πŸ›‘οΈ The Hardware Overflow Rule & Sign Extension​

When can an arithmetic overflow physically occur?

πŸ“The Fundamental Law of Signed Overflowformula

Signed overflow can occur if and only if two numbers with the same sign are added, and the result produces the opposite sign:

  1. (+)+(+)=(βˆ’)(+) + (+) = (-) β€…β€ŠβŸΉβ€…β€Š\implies Positive Overflow (V=1V = 1)
  2. (βˆ’)+(βˆ’)=(+)(-) + (-) = (+) β€…β€ŠβŸΉβ€…β€Š\implies Negative Overflow (V=1V = 1)

Adding numbers of opposite signs ((+)+(βˆ’)(+) + (-) or (βˆ’)+(+)(-) + (+)) CAN NEVER OVERFLOW, because the magnitude of the sum is strictly smaller than the largest operand!

Silicon Hardware Implementation of VV​

In hardware, testing operand signs using comparators is unnecessary. The CPU calculates overflow using a single 2-input XOR gate:

πŸ“Hardware Overflow Equationformula
V=Cin(MSB)βŠ•Cout(MSB)V = C_{\text{in(MSB)}} \oplus C_{\text{out(MSB)}}

Where:

  • Cin(MSB)C_{\text{in(MSB)}} is the carry entering the most significant full adder stage (Cnβˆ’1C_{n-1}).
  • Cout(MSB)C_{\text{out(MSB)}} is the carry leaving the most significant full adder stage (CnC_n).

If a carry enters the MSB stage but does not leave it (Cin=1,Cout=0C_{in}=1, C_{out}=0), or leaves without entering (Cin=0,Cout=1C_{in}=0, C_{out}=1), the sign bit was corrupted, and V=1V = 1!

Sign Extension in Microprocessors​

When a processor loads an 8-bit signed integer into a 32-bit register (e.g. int8_t to int32_t), how does it preserve negative values?

  • Zero Extension (Unsigned): Pad high bits with 00s (movzx).
  • Sign Extension (Signed): Replicate the MSB (sign bit) across all higher-order bit positions (movsx).

Proof: Why Sign Extension Preserves Value​

Consider 4-bit βˆ’5=10112-5 = 1011_2. Extending to 8 bits by replicating the MSB (11):

111110112=βˆ’27+26+25+24+23+0+21+20=βˆ’128+64+32+16+8+2+1=βˆ’51011111011_2 = -2^7 + 2^6 + 2^5 + 2^4 + 2^3 + 0 + 2^1 + 2^0 = -128 + 64 + 32 + 16 + 8 + 2 + 1 = \mathbf{-5}_{10}

Because βˆ’2k+2kβˆ’1+2kβˆ’2+β‹―+20=βˆ’1-2^k + 2^{k-1} + 2^{k-2} + \dots + 2^0 = -1, copying ones to the left mathematically preserves the negative value identically!


🌊 Real Numbers: Fixed-Point vs. Floating-Point​

In Fixed-Point representation, a fixed number of bits is allocated to the integer part and a fixed number to the fractional part (e.g., Q4.4Q4.4 format allocates 4 bits integer, 4 bits fraction). Fixed-point is fast on DSP chips without hardware FPUs, but its dynamic range is cripplingly narrow.

In Floating-Point representation, the number is expressed in binary scientific format:

N=(βˆ’1)SΓ—MΓ—2EN = (-1)^S \times M \times 2^E

Where:

  • SS is the Sign bit (0=positive,1=negative0 = \text{positive}, 1 = \text{negative}).
  • MM is the Significand / Mantissa (the normalized precision bits).
  • EE is the Exponent (the power-of-two scaling factor).

πŸ›οΈ IEEE 754 Floating-Point Standard​

Established in 1985 (and updated in 2008/2019), the IEEE 754 Standard governs all modern floating-point silicon units (FPUs).

IEEE 802.3 StandardTotal Frame: 64 to 1518 Bytes

IEEE 754 Single-Precision (32-Bit Float) Bit Allocation

Sign (S)
Bytes
Biased Exponent (E)
Bytes
Fraction / Mantissa (M)
Bytes
BytesSign (S)

0 = Positive (+), 1 = Negative (-)

The Hidden Bit (Implicit 1) Trick​

In base-2, any non-zero number in scientific notation always begins with a leading 1 (e.g. 1.0112Γ—231.011_2 \times 2^3). Because the leading digit is guaranteed to be 1, IEEE 754 does not waste a bit storing it! The stored 23-bit mantissa represents only the fractional part after the radix point. The hardware FPU automatically prepends the implicit 1.1. during calculation, gaining 24 bits of precision from a 23-bit field!

πŸ“Reconstructed IEEE 754 Single Precision Valueformula
Value=(βˆ’1)SΓ—(1+βˆ‘i=123b23βˆ’iβ‹…2βˆ’i)Γ—2Eβˆ’127\text{Value} = (-1)^S \times \left( 1 + \sum_{i=1}^{23} b_{23-i} \cdot 2^{-i} \right) \times 2^{E - 127}

Step-by-Step Walkthrough: Converting βˆ’13.62510-13.625_{10} to IEEE 754 32-Bit Float​

  1. Determine Sign: The number is negative β€…β€ŠβŸΉβ€…β€ŠS=1\implies \mathbf{S = 1}.
  2. Convert Absolute Value to Binary:
    • Integer: 1310=1101213_{10} = 1101_2
    • Fraction: 0.62510=(0.5+0.125)=0.10120.625_{10} = (0.5 + 0.125) = 0.101_2
    • Combined: 13.62510=1101.101213.625_{10} = 1101.101_2
  3. Normalize: 1101.1012=1.1011012Γ—231101.101_2 = \mathbf{1.101101}_2 \times 2^3
  4. Calculate Biased Exponent:
    • True exponent e=3e = 3.
    • Biased Exponent E=e+Bias=3+127=130E = e + \text{Bias} = 3 + 127 = 130.
    • 13010=100000102130_{10} = \mathbf{10000010}_2 (8 bits).
  5. Extract 23-Bit Mantissa:
    • Drop the implicit leading 1.1.: remaining fraction is 101101101101.
    • Pad with trailing zeros to 23 bits: 10110100000000000000000\mathbf{10110100000000000000000}
  6. Assemble the 32 Bits:
    Sign (1b):     1
    Exponent (8b): 10000010
    Mantissa (23b): 10110100000000000000000

    Full 32-bit: 1 10000010 10110100000000000000000
    Group Hex: 1100 0001 0101 1010 0000 0000 0000 0000
    Hex Code: 0xC15A0000

πŸ•³οΈ Special Values: Β±0\pm 0, Subnormals, ±∞\pm \infty, and NaN\text{NaN}​

IEEE 754 reserves special exponent patterns (E=0E = 0 and E=255E = 255) to represent mathematical boundary conditions without crashing the CPU:

Exponent Field (EE)Fraction Field (MM)Mathematical InterpretationFormula / Real Value
0000 0000 (00)0000...00 (All 0s)Zero(βˆ’1)SΓ—0.0(-1)^S \times 0.0 (Β±0\pm 0 depending on Sign bit)
0000 0000 (00)Non-zero (Mβ‰ 0M \ne 0)Subnormal / Denormalized(βˆ’1)SΓ—0.MΓ—2βˆ’126(-1)^S \times 0.M \times 2^{-126} (Gradual underflow)
0000 0001 .. 1111 1110 (1..2541..254)Any bit patternNormalized Number(βˆ’1)SΓ—1.MΓ—2Eβˆ’127(-1)^S \times 1.M \times 2^{E-127} (Standard float)
1111 1111 (255255)0000...00 (All 0s)Infinity±∞\pm \infty (e.g. division by zero: 1.0/0.01.0 / 0.0)
1111 1111 (255255)Non-zero (Mβ‰ 0M \ne 0)Not a Number (NaN)Invalid operation (e.g. 0.0/0.00.0 / 0.0, βˆ’1\sqrt{-1})
  • Gradual Underflow (Subnormal Numbers): When E=0E = 0 and Mβ‰ 0M \ne 0, the implicit bit becomes 0.0. instead of 1.1., and the true exponent is fixed at βˆ’126-126. This allows floating-point numbers to approach zero gradually without a sudden underflow step cliff!

πŸŽ›οΈ Interactive IEEE 754 32-Bit Floating-Point Inspector​

Type any real number or click any individual bit inside the 32-bit register to toggle it live. Observe how the sign, biased exponent, implicit bit, and reconstructed mathematical values respond instantaneously:

Interactive 32-Bit Register (Click any bit to flip it!):MSB [31] βž” LSB [0]
131
130
029
028
027
026
025
124
023
122
021
120
119
018
117
016
015
014
013
012
011
010
09
08
07
06
05
04
03
02
01
00
Sign (1 Bit: [31]) = - (Negative)
Biased Exponent (8 Bits: [30..23]) = 130
Mantissa Fraction (23 Bits: [22..0])
1. Sign Component (S)
(-1)1 = -1
2. True Exponent (E - Bias)
2(130 - 127) = 23
Bias = 127 (Single Precision)
3. Significand / Mantissa (M)
1.703125
Normalized (Hidden bit is 1)
Full Reconstructed IEEE-754 Formula
(-) 1.7031250 Γ— 23 = -13.625

🏭 Real-World Production Context: Hardware FPUs & ALU Status Register Flags​

In modern microprocessors, arithmetic units and floating-point co-processors bridge compiler data types with high-speed transistor datapaths.

Hardware Arithmetic & Floating-Point Pipeline Hierarchy

Software Level

Primitive Data Types & Compilers

πŸ’»

Compilers (GCC, Clang, Rustc) emit integer add/sub and floating-point SIMD instructions based on signed types and IEEE 754 standards.

int32_t / int64_tfloat (binary32) / double (binary64)Branch Conditions (jge, jl)
↓Compiled to Machine Code
Processor Register File

CPU Status Registers (EFLAGS / CPSR)

🚩

Execution updates hardware condition flags: Carry (C), Overflow (V), Sign (S), and Zero (Z) to guide conditional execution.

C: Unsigned Carry / BorrowV: Signed 2's Comp OverflowZ: Zero Result Flag
↓Pipelined to Execution Units
Execution Datapath

Vector Floating-Point Units (FPUs)

⚑

High-throughput execution units (AVX-512, ARM NEON) perform IEEE 754 arithmetic with barrel shifters and exponent aligners.

Implicit Leading 1 AlignmentFused Multiply-Add (FMA)Subnormal Gradual Underflow
↓Transistor Gate Array Switching
Silicon Hardware

Arithmetic Logic Units & Carry Trees

πŸ”¬

Ultra-fast Kogge-Stone/Brent-Kung carry trees and single-gate XOR overflow detectors (V = Cin ^ Cout) evaluate in picoseconds.

V = Cin ^ Cout DetectorXOR Inversion BankKogge-Stone Carry Lookahead
  • ALU Status Register Architecture: Modern microprocessors execute billions of arithmetic operations per second while maintaining hardware condition flags (EFLAGS on x86, CPSR on ARM). The Carry Flag (CC) detects unsigned integer wrapping, while the Overflow Flag (VV) is evaluated via a single hardware XOR gate (V=CinβŠ•CoutV = C_{in} \oplus C_{out}) to catch 2's complement numeric range violations.
  • IEEE 754 Silicon Implementations: Floating-point units (FPUs) inside modern CPUs and GPUs contain dedicated barrel shifters to align mantissas during addition/subtraction. By adopting an Excess-127 biased exponent, hardware can compare floating-point magnitudes using standard unsigned integer comparators without two's complement conversion overhead.

πŸ“ Numerical Applications & Worked Examples​

Example 1: Signed 2's Complement Addition, Overflow Detection & Flag Evaluation​

Problem Statement:
Given two 8-bit signed 2's complement numbers A=(+75)10A = (+75)_{10} and B=(+85)10B = (+85)_{10}:

  1. Convert both to 8-bit binary representations.
  2. Perform binary addition A+BA + B.
  3. Identify the carries entering and leaving the MSB stage (Cin(MSB)C_{in(MSB)} and Cout(MSB)C_{out(MSB)}).
  4. Determine the values of the Overflow Flag (VV) and Carry Flag (CC).
  5. Interpret the resulting 8-bit pattern if read as a signed 2's complement number versus an unsigned number.

Step-by-Step Solution:

  1. Convert to 8-Bit Signed Binary:

    • A=(+75)10=64+8+2+1=010010112A = (+75)_{10} = 64 + 8 + 2 + 1 = 01001011_2
    • B=(+85)10=64+16+4+1=010101012B = (+85)_{10} = 64 + 16 + 4 + 1 = 01010101_2
  2. Column-by-Column Addition:

01001011(+75)+01010101(+85)10100000(RawΒ 8-bitΒ sum)\begin{array}{rl} 01001011 & (+75) \\ + 01010101 & (+85) \\ \hline 10100000 & (\text{Raw 8-bit sum}) \end{array}
  1. Trace Internal Carries:

    • Bit 0: 1+1=01 + 1 = 0, carry to bit 1 =1= 1
    • Bit 1: 1+0+1=01 + 0 + 1 = 0, carry to bit 2 =1= 1
    • Bit 2: 0+1+1=00 + 1 + 1 = 0, carry to bit 3 =1= 1
    • Bit 3: 1+0+1=01 + 0 + 1 = 0, carry to bit 4 =1= 1
    • Bit 4: 0+1+1=00 + 1 + 1 = 0, carry to bit 5 =1= 1
    • Bit 5: 0+0+1=10 + 0 + 1 = 1, carry to bit 6 =0= 0
    • Bit 6: 1+1+0=01 + 1 + 0 = 0, carry to bit 7 =1β€…β€ŠβŸΉβ€…β€ŠCin(MSB)=1= 1 \implies C_{in(MSB)} = 1
    • Bit 7 (MSB): 0+0+1=10 + 0 + 1 = 1, carry out of bit 7 =0β€…β€ŠβŸΉβ€…β€ŠCout(MSB)=0= 0 \implies C_{out(MSB)} = 0
  2. Evaluate Hardware Flags:

    • Overflow Flag (VV): V=Cin(MSB)βŠ•Cout(MSB)=1βŠ•0=1(OverflowΒ Occurred!)V = C_{in(MSB)} \oplus C_{out(MSB)} = 1 \oplus 0 = \mathbf{1} \quad (\text{Overflow Occurred!})
    • Carry Flag (CC): C=Cout(MSB)=0C = C_{out(MSB)} = \mathbf{0}
  3. Interpret Results:

    • Signed Interpretation: The sum of two positive numbers (+75+75 and +85+85) yielded an MSB of 11 (negative sign bit). The raw pattern 10100000210100000_2 in 2's complement equals: βˆ’(2’sΒ complementΒ ofΒ 101000002)=βˆ’(011000002)=βˆ’(64+32)=βˆ’9610-(2\text{'s complement of } 10100000_2) = -(01100000_2) = -(64 + 32) = \mathbf{-96}_{10} Because the true mathematical sum +160+160 exceeds the maximum 8-bit signed bound of +127+127 ([βˆ’128,+127][-128, +127]), the result wrapped around, corrupting the sign bit. The hardware asserted V=1V=1 to alert the operating system.
    • Unsigned Interpretation: As an unsigned integer, 101000002=128+32=1601010100000_2 = 128 + 32 = \mathbf{160}_{10}. Since 160≀255160 \le 255, the unsigned calculation is fully correct, and C=0C=0 confirms no unsigned carry overflow occurred.

Example 2: Decimal Real Number to IEEE 754 Single-Precision 32-Bit Hexadecimal​

Problem Statement:
Encode the real decimal number N=βˆ’118.62510N = -118.625_{10} into the IEEE 754 Single-Precision (32-bit float) format. Present the exact bit partition (Sign, Biased Exponent, Mantissa) and convert the final 32-bit sequence into hexadecimal format.

Step-by-Step Solution:

  1. Determine the Sign Bit (SS):
    Since N=βˆ’118.625N = -118.625 is negative, the Sign Bit is: S=1\mathbf{S = 1}

  2. Convert Absolute Magnitude ∣N∣=118.62510|N| = 118.625_{10} to Binary:

    • Integer Part (11810118_{10}): 118=64+32+16+4+2=(1110110)2118 = 64 + 32 + 16 + 4 + 2 = (1110110)_2
    • Fractional Part (0.625100.625_{10}): 0.625=0.5+0.125=2βˆ’1+2βˆ’3=(0.101)20.625 = 0.5 + 0.125 = 2^{-1} + 2^{-3} = (0.101)_2
    • Combined Binary Representation: (118.625)10=(1110110.101)2(118.625)_{10} = (1110110.101)_2
  3. Normalize into Binary Scientific Notation:
    Shift the radix point 6 positions to the left so that exactly one non-zero digit precedes it: 1110110.1012=1.1101101012Γ—261110110.101_2 = \mathbf{1.110110101}_2 \times 2^6

    • True Exponent: e=6e = 6.
  4. Compute the Biased Exponent (EE):
    For IEEE 754 Single-Precision, the exponent bias is 127127: E=e+Bias=6+127=13310E = e + \text{Bias} = 6 + 127 = 133_{10} Converting 13310133_{10} to an 8-bit unsigned binary integer: 133=128+4+1β€…β€ŠβŸΉβ€…β€ŠE=100001012133 = 128 + 4 + 1 \implies \mathbf{E = 10000101}_2

  5. Extract the 23-Bit Fractional Significand (MM):
    Drop the implicit leading 1.1. from the normalized mantissa 1.11011010121.110110101_2:

    • Fractional bits: 110110101110110101 (9 bits).
    • Pad with 14 trailing zeros to fill the required 23-bit width: M=110110101000000000000002\mathbf{M = 11011010100000000000000}_2
  6. Assemble the 32-Bit Frame and Group into Hexadecimal:
    Concatenate the fields [Sβ€…β€Š(1b)]β€…β€Š[Eβ€…β€Š(8b)]β€…β€Š[Mβ€…β€Š(23b)][S \; (1\text{b})] \; [E \; (8\text{b})] \; [M \; (23\text{b})]:

FieldBit LengthBinary Pattern
Sign (SS)11
Exponent (EE)81000 0101
Mantissa (MM)23110 1101 0100 0000 0000 0000

Grouping into 4-bit nibbles from MSB to LSB:

  • 1100 β†’\to C
  • 0010 β†’\to 2
  • 1110 β†’\to E
  • 1101 β†’\to D
  • 0100 β†’\to 4
  • 0000 β†’\to 0
  • 0000 β†’\to 0
  • 0000 β†’\to 0

Final Hexadecimal Representation:
0xC2ED4000\mathbf{\text{0xC2ED4000}}


Example 3: Reconstructing Decimal Value from IEEE 754 32-Bit Hex Pattern​

Problem Statement:
An embedded telemetry register reads a 32-bit floating-point word stored in memory as 0x42E48000. Deconstruct the bit fields, determine the numeric classification (Normalized, Subnormal, Special), and calculate the exact real decimal value.

Step-by-Step Solution:

  1. Expand Hexadecimal to 32 Binary Bits:

    • 4 β†’\to 0100
    • 2 β†’\to 0010
    • E β†’\to 1110
    • 4 β†’\to 0100
    • 8 β†’\to 1000
    • 0 β†’\to 0000
    • 0 β†’\to 0000
    • 0 β†’\to 0000

    Complete 32-bit string: 0100β€…β€Š0010β€…β€Š1110β€…β€Š0100β€…β€Š1000β€…β€Š0000β€…β€Š0000β€…β€Š0000\mathbf{0100 \; 0010 \; 1110 \; 0100 \; 1000 \; 0000 \; 0000 \; 0000}

  2. Partition Bit Fields:

    • Bit 31 (Sign SS): 0 β€…β€ŠβŸΉβ€…β€Š\implies The number is positive (+1+1).
    • Bits [30..23] (Biased Exponent EE): 1000 0101 E=128+4+1=13310E = 128 + 4 + 1 = 133_{10}
    • Bits [22..0] (Mantissa Fraction MM): 110 0100 1000 0000 0000 0000 Fraction bits: .110010012.11001001_2
  3. Classification & True Exponent Calculation:

    • Since 1≀E≀2541 \le E \le 254, the number is a standard Normalized Number.
    • True exponent: e=Eβˆ’Bias=133βˆ’127=6e = E - \text{Bias} = 133 - 127 = \mathbf{6}
  4. Reconstruct Normalized Significand: Prepend the implicit leading 1.1. before the fractional mantissa: Significand=1.M=1.110010012\text{Significand} = 1.M = 1.11001001_2

  5. Evaluate True Binary Value: Multiply the significand by 2e=262^e = 2^6 (shift radix point 6 places right): 1.110010012Γ—26=1110010.0121.11001001_2 \times 2^6 = 1110010.01_2

  6. Convert to Decimal:

    • Integer part (111001021110010_2): 64+32+16+2=1141064 + 32 + 16 + 2 = 114_{10}
    • Fractional part (0.0120.01_2): 0Γ—2βˆ’1+1Γ—2βˆ’2=14=0.25100 \times 2^{-1} + 1 \times 2^{-2} = \frac{1}{4} = 0.25_{10}

    Final Reconstructed Decimal Value:
    +114.2510\mathbf{+114.25_{10}}


🎯 Exam & Interview Pitfall Check​

Core Conceptual Questions
  • Why is an Exponent Bias of 127 used in IEEE 754 instead of 2's complement?
    If exponents were stored in 2's complement, comparing two floating-point numbers would require complex signed arithmetic. By adding a bias of 127, all negative exponents (2βˆ’1262^{-126} to 2+1272^{+127}) become positive unsigned integers (11 to 254254). A CPU can therefore sort and compare floating-point magnitudes using fast, low-power unsigned integer hardware comparators!
  • How does the ALU determine if an addition has overflowed in hardware?
    By computing V=Cin(MSB)βŠ•Cout(MSB)V = C_{\text{in(MSB)}} \oplus C_{\text{out(MSB)}}. If the carry arriving at the MSB stage differs from the carry leaving it, the sign bit was corrupted, immediately asserting the Overflow flag.
Common Interview Traps
  • Trap: Confusing the Carry flag with the Overflow flag.
    • Adding unsigned numbers? Check the Carry flag (CC).
    • Adding signed numbers? Check the Overflow flag (VV).
      A calculation can have C=1C=1 and V=0V=0 (e.g. βˆ’1+βˆ’1=βˆ’2-1 + -1 = -2), or C=0C=0 and V=1V=1 (e.g. +70++70=βˆ’116+70 + +70 = -116), or both, or neither!
  • Trap: Forgetting the Implicit Leading 1 in IEEE 754.
    When decoding IEEE 754 mantissa bits, always remember to add the implicit 1.1. before multiplying by 2e2^e. The only exception is when the exponent field is all zeros (E=0E = 0), which indicates a subnormal number with an implicit 0.0..

πŸ’¬

Discussion & Doubts