Module 02: Integer Representation & Fixed-Point Arithmetic
Tags: #◇Computer Science #◇CSARCH2 #◇Computer Architecture #◇Hardware Modeling #◇Integer Representation & Fixed-Point Arithmetic
◇Overview
Digital computers represent all data—integers, memory addresses, text characters, and machine instructions—as discrete binary bit patterns. This module establishes the mathematical foundations of positional number systems, arbitrary radix base conversions, and binary data organization from individual bits to quad-words. We examine byte-ordering memory mechanics (Little Endian vs. Big Endian), metric prefix standards ( binary IEC vs. decimal SI), and compare signed integer encoding schemes: Sign & Magnitude, 1's Complement, 2's Complement, and Excess- biased notations. Character encodings (ASCII, Unicode UTF-8/UTF-16/UTF-32) and decimal representations (Packed BCD and Densely Packed BCD) are also formalized.
◇Key Definitions
- Radix (Base ): The total number of unique digit symbols available in a positional numeral system (e.g., for Binary, for Octal, for Decimal, for Hexadecimal).
- Positional Weight: The numerical value assigned to a digit position, given by , where represents the integer distance relative to the radix point.
- Crumb / Nibble / Byte: Fundamental binary groupings of 2 bits (crumb), 4 bits (nibble, representing 1 hexadecimal digit), and 8 bits (byte, the standard smallest addressable unit).
- Little Endian: A byte-ordering convention where the Least Significant Byte (LSB) of a multi-byte word is stored at the lowest numerical memory address.
- Big Endian: A byte-ordering convention where the Most Significant Byte (MSB) of a multi-byte word is stored at the lowest numerical memory address.
- 2's Complement: The primary hardware representation for signed integers where a negative number is represented as , providing a unique representation for zero and straightforward arithmetic hardware.
- Sign Extension: The operation of replicating the Most Significant Bit (MSb / sign bit) across higher-order bit positions when promoting an -bit signed integer to a wider word width (e.g., 8-bit to 16-bit).
- Zero Extension: The operation of appending leading zeros to the MSb positions when promoting an unsigned integer to a wider word width.
- Densely Packed BCD (DPD): An efficient compression scheme that encodes 3 Binary-Coded Decimal digits (12 bits) into exactly 10 bits using boolean selection maps.
◇Theoretical Framework / Core Concepts
1. Positional Number Systems and Radix Formulation
In any base- positional numeral system, a number string evaluates to:
where each digit .
Positional Weight Array:
Position (i): ... 3 2 1 0 . -1 -2 -3 ...
Weight (r^i): ... r^3 r^2 r^1 r^0 . r^-1 r^-2 r^-3 ...
Base 10: ... 1000 100 10 1 . 0.1 0.01 0.001 ...
Base 2: ... 8 4 2 1 . 0.5 0.25 0.125 ...
Base Conversion Algorithms:
- Integer Part (): Successive division by radix . The remainders produced at each step correspond to digits read from bottom to top (Least Significant to Most Significant).
- Fractional Part (): Successive multiplication by radix . The integer part peeled off at each step corresponds to fractional digits read from top to bottom.
- Power-of-2 Grouping: Direct translation between bases where :
- Binary to Octal (): Group binary bits into sets of 3 from the radix point outward.
- Binary to Hexadecimal (): Group binary bits into sets of 4 from the radix point outward.
- General Base- to Base-: Convert Base-.
2. Binary Data Organization & Endianness
Modern computer architectures define hierarchical data units:
+---------------------------------------------------------------+
| Quad-word (128 bits / 16 bytes) |
+-------------------------------+-------------------------------+
| Double-word (64 bits / 8 bytes)| Double-word |
+---------------+---------------+---------------+---------------+
| Word (32 bits)| Word | Word | Word |
+-------+-------+-------+-------+-------+-------+-------+-------+
| H-Word| H-Word| H-Word| H-Word| H-Word| H-Word| H-Word| H-Word|
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| B | B | B | B | B | B | B | B | B | B | B | B | B | B | B | B | (Bytes)
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| Nibble (4b) | Nibble | Nibble | Nibble |
+---------------+---------------+---------------+---------------+
| Crumb (2b) | Crumb | Crumb | Crumb |
+---------------+---------------+---------------+---------------+
| Bit (1b) | Bit | Bit | Bit |
+---------------+---------------+---------------+---------------+
Byte Ordering (Endianness):
Consider the 32-bit hexadecimal value 0x1A2B3C4D stored at base memory address 0x1000:
- Byte breakdown:
MSB = 0x1A,Byte 1 = 0x2B,Byte 2 = 0x3C,LSB = 0x4D.
Memory Address | Little Endian (x86 / ARM) | Big Endian (Network / SPARC)
---------------+---------------------------+-----------------------------
0x1000 | 0x4D (LSB) | 0x1A (MSB)
0x1001 | 0x3C | 0x2B
0x1002 | 0x2B | 0x3C
0x1003 | 0x1A (MSB) | 0x4D (LSB)
3. Metric Prefix Standards ( vs. )
Architectural specifications must distinguish between decimal storage units (SI) and binary memory units (IEC):
| Metric Prefix (SI, ) | Exact Decimal Value | Binary Prefix (IEC, ) | Exact Binary Value | Discrepancy () |
|---|---|---|---|---|
| Kilobyte (KB) | Kibibyte (KiB) | |||
| Megabyte (MB) | Mebibyte (MiB) | |||
| Gigabyte (GB) | Gibibyte (GiB) | |||
| Terabyte (TB) | Tebibyte (TiB) |
Rule of Thumb: Primary memory (RAM, CPU Caches) uses binary IEC units (). Storage media (HDDs, SSDs, Flash) and network transmission bandwidths use decimal SI units ().
4. Comparison of Signed Integer Representations
For an -bit binary word:
| System | MSB Meaning | Representation of | Valid Number Range | Zero Representation |
|---|---|---|---|---|
| Unsigned | Value | N/A | Unique (00...0) | |
| Sign & Magnitude | Sign () | Invert MSB only | Dual () | |
| 1's Complement | Negative weight | Invert all bits () | Dual () | |
| 2's Complement | weight | Invert all bits | Unique (00...0) | |
| Excess- (Biased) | Offset encoding | Unique () |
Why 2's Complement is Universally Adopted:
- Unique Zero: Eliminates dual-zero hardware comparison ambiguity.
- Simplified Adder/Subtractor: Subtraction is performed as , reusing identical adder circuitry.
- Asymmetric Range: Exactly one extra negative value (), eliminating wasted bit patterns.
5. Character & Decimal Encodings
- ASCII: 7-bit standard (128 characters), partitioned into Control (
0x00..0x1F), Digits/Punctuation (0x20..0x3F), Uppercase (0x40..0x5F), Lowercase (0x60..0x7F). - Unicode Architecture: 17 planes of code points ( to ):
- Plane 0 (BMP - Basic Multilingual Plane): .
- UTF-8: Variable length (1 to 4 bytes) prefix code. ASCII backwards-compatible.
- UTF-16: Encodes BMP directly as 16-bit words. Encodes Supplementary Planes () using Surrogate Pairs:
- Binary-Coded Decimal (BCD):
- Packed BCD: Two 4-bit digits per byte. Sign nibbles:
0xC() for positive/credit,0xD() for negative/debit. - Densely Packed BCD (DPD): Encodes 3 decimal digits () into 10 bits () using boolean declet maps.
- Packed BCD: Two 4-bit digits per byte. Sign nibbles:
◇Worked Examples / Calculations / Hardware Traces
Example 1: Arbitrary Radix Base Conversion with Fractions
Problem: Convert to:
- Binary (Base 2)
- Octal (Base 8)
- Hexadecimal (Base 16)
Solution:
-
Step 1: Integer Part via successive division:
Read upward: .
-
Step 2: Fractional Part via successive multiplication:
Read downward: .
-
Combined Binary: .
-
Octal Conversion (Group 3 bits):
- Integer:
- Fraction:
- Result: .
-
Hexadecimal Conversion (Group 4 bits):
- Integer:
- Fraction:
- Result: .
Example 2: Little Endian vs. Big Endian Multi-Byte Tracing
Problem: A program writes the 64-bit unsigned integer 0x0123456789ABCDEF to memory starting at address 0x2000. Show the byte-by-byte memory layout in hexadecimal for both Little Endian and Big Endian systems.
Solution:
Address | Little Endian (LSB First) | Big Endian (MSB First)
---------+---------------------------+-----------------------
0x2000 | 0xEF | 0x01
0x2001 | 0xCD | 0x23
0x2002 | 0xAB | 0x45
0x2003 | 0x89 | 0x67
0x2004 | 0x67 | 0x89
0x2005 | 0x45 | 0xAB
0x2006 | 0x23 | 0xCD
0x2007 | 0x01 | 0xEF
Example 3: UTF-16 Surrogate Pair Encoding
Problem: Calculate the UTF-16 surrogate pair encoding for the musical symbol character at Unicode code point (G-clef).
Solution:
- Subtract base offset:
- Convert offset to 20-bit binary:
- Split into two 10-bit chunks ( and ):
- High 10 bits ():
- Low 10 bits ():
- Compute High Surrogate ():
- Compute Low Surrogate ():
Final UTF-16 Encoding: 0xD834 0xDD1E.
◇Complexity Analysis / Common Pitfalls
- Confusing SI () and IEC () Storage Capacity: When a customer purchases a "1 TB" SSD (), the operating system (which measures in binary ) reports , leading to perceived capacity loss.
- Sign-Extension vs. Zero-Extension Mistakes: Zero-extending a negative 2's complement number corrupts its value. For example, promoting 8-bit
-5(0xFB) to 16-bit unsigned yields0x00FB(), whereas proper sign-extension yields0xFFFB(). - Surrogate Code Point Collisions: The Unicode Consortium permanently reserved the range exclusively for UTF-16 surrogate pairs; no valid standalone character may ever be assigned to this range in Plane 0.
◇References & Navigation
ACTIVE RECALL VERIFICATION
Select an answer to verify conceptual comprehension and reveal the technical rationale.
In an 8-bit system, what is the 2's complement representation of decimal integer ?
A 32-bit integer stored at memory address 0x0040 contains the bytes 0x78, 0x56, 0x34, 0x12 at addresses 0x0040, 0x0041, 0x0042, and 0x0043 respectively. What is the hexadecimal integer value if the architecture is Little Endian?
What is the valid representation range for an 8-bit signed integer in 1's complement versus 2's complement?
How many decimal digits can be compressed into 10 bits using Densely Packed BCD (DPD)?
Which Unicode transformation format is always backward-compatible with 7-bit ASCII without modifying byte values?