Problem Set - Integer Representation
Tags: #◇Computer Science #◇CSARCH2 #◇Computer Architecture #◇Binary Arithmetic #◇Data Representation #◇Two's Complement
◇Overview
In digital computer systems and ◇Computer Architecture, fixed-width binary words encode numerical values using distinct conventions. Selecting an encoding scheme impacts the hardware complexity of arithmetic units (such as the ◇ALU), the numerical dynamic range, and the representation of negative values.
┌──────────────────────────────────────────────────────────┐
│ Integer Representation │
└────────────────────────────┬─────────────────────────────┘
│
┌───────────────────────────────┴───────────────────────────────┐
▼ ▼
┌─────────────────────────┐ ┌─────────────────────────┐
│ Unsigned Integers │ │ Signed Integers │
│ [0, 2^n - 1] │ │ (Multiple Conventions) │
└─────────────────────────┘ └────────────┬────────────┘
│
┌───────────────────────────┬─────────────────────────────────┴────────────────────────────┐
▼ ▼ ▼ ▼
┌─────────────────────────┐ ┌─────────────────────────┐ ┌─────────────────────────┐ ┌─────────────────────────┐
│ Sign-and-Magnitude │ │ 1's Complement │ │ 2's Complement │ │ Biased / Excess-K │
│ [-(2^(n-1)-1), │ │ [-(2^(n-1)-1), │ │ [-2^(n-1), │ │ [0 - K, 2^n - 1 - K] │
│ 2^(n-1)-1] │ │ 2^(n-1)-1] │ │ 2^(n-1) - 1] │ │ (Used in IEEE 754 exp)│
│ Dual Zeros (+0, -0) │ │ Dual Zeros (+0, -0) │ │ Unique Zero (00...0) │ └─────────────────────────┘
└─────────────────────────┘ └─────────────────────────┘ └─────────────────────────┘
Representation Schemes Comparison (-bit word)
-
Unsigned Binary Representation:
- Evaluated as standard base-2 positional notation:
- Dynamic Range: . For a 16-bit word (), the range is .
- Evaluated as standard base-2 positional notation:
-
Sign-and-Magnitude (SM):
- The Most Significant Bit (MSB, ) serves as the sign flag (), while the remaining bits encode the absolute magnitude.
- Dynamic Range: . For : .
- Drawback: Dual representations for zero ( and ), requiring extra hardware comparison logic.
- The Most Significant Bit (MSB, ) serves as the sign flag (), while the remaining bits encode the absolute magnitude.
-
1's Complement (Diminished Radix Complement):
- Positive values follow standard binary. Negative values are formed by inverting every bit (logical NOT operation):
- Dynamic Range: . For : .
- Drawback: Contains dual zeros ( and ) and requires end-around carry addition logic.
- Positive values follow standard binary. Negative values are formed by inverting every bit (logical NOT operation):
-
2's Complement (Radix Complement):
- Universal standard in modern microprocessors. Negation of is formed by inverting all bits and adding ().
- Dynamic Range: . For : .
- Advantage: Exactly one representation for zero (), and identical adder circuitry executes both addition and subtraction without sign pre-checks. The asymmetric extra negative value (, represented as ) is often referred to as the weird number or most negative number.
- Universal standard in modern microprocessors. Negation of is formed by inverting all bits and adding ().
-
Sign Extension vs. Zero Extension:
- Sign Extension (Signed Values): Replicates the MSB across higher-order bit positions when widening an -bit integer to an -bit integer ().
- Zero Extension (Unsigned Values): Appends leading zeros to preserve unsigned magnitude:
- Sign Extension (Signed Values): Replicates the MSB across higher-order bit positions when widening an -bit integer to an -bit integer ().
◇Problem Set 1: Decimal to 16-Bit Binary Representation
Instructions: Represent the following decimal integers in the specified 16-bit binary representation. If the number cannot be represented within the format's dynamic range, designate as N/A.
Summary Solution Table
| Decimal Value | 16-bit 2's Complement | 16-bit 1's Complement | 16-bit Sign and Magnitude | 16-bit Unsigned Representation |
|---|---|---|---|---|
| 0.) Range | ||||
| 1.) | 0000 0000 0111 1101 | 0000 0000 0111 1101 | 0000 0000 0111 1101 | 0000 0000 0111 1101 |
| 2.) | 1111 1111 0000 0010 | 1111 1111 0000 0001 | 1000 0000 1111 1110 | N/A |
| 3.) | N/A | N/A | N/A | 1111 1111 1111 1110 |
| 4.) | 1000 0000 0000 0000 | N/A | N/A | N/A |
Step-by-Step Derivations
Problem 0: Theoretical Dynamic Ranges ()
-
16-bit 2's Complement:
- Minimum: (Binary:
1000 0000 0000 0000) - Maximum: (Binary:
0111 1111 1111 1111) - Range:
- Minimum: (Binary:
-
16-bit 1's Complement:
- Minimum: (Binary:
1000 0000 0000 0000) - Maximum: (Binary:
0111 1111 1111 1111) - Range:
- Minimum: (Binary:
-
16-bit Sign and Magnitude:
- Minimum: (Binary:
1111 1111 1111 1111) - Maximum: (Binary:
0111 1111 1111 1111) - Range:
- Minimum: (Binary:
-
16-bit Unsigned:
- Minimum: (Binary:
0000 0000 0000 0000) - Maximum: (Binary:
1111 1111 1111 1111) - Range:
- Minimum: (Binary:
Problem 1: Value
-
Binary Conversion of Magnitude:
-
Zero-extended to 16 bits:
-
Format Encoding:
- 16-bit 2's complement: Positive number, sign bit
0000 0000 0111 1101 - 16-bit 1's complement: Positive number, identical to true binary
0000 0000 0111 1101 - 16-bit Sign and Magnitude: MSB is (positive), 15 magnitude bits
0000 0000 0111 1101 - 16-bit Unsigned:
0000 0000 0111 1101
- 16-bit 2's complement: Positive number, sign bit
Problem 2: Value
-
Binary Conversion of Magnitude ():
16-bit positive pattern:
-
Format Encoding:
- 16-bit Unsigned:
-
, strictly outside N/A
2. 16-bit Sign and Magnitude: -
Set MSB () to (negative sign indicator).
-
Remaining 15 bits represent magnitude .
-
Bit string:
1000 0000 1111 1110
3. 16-bit 1's Complement: -
Invert all 16 bits of :
-
Bit string:
1111 1111 0000 0001
4. 16-bit 2's Complement: -
Add to the 1's complement representation:
-
Bit string:
1111 1111 0000 0010
Problem 3: Value
-
Range Verification:
- 16-bit signed maximum is .
- Because , this value causes signed representation overflow.
- 16-bit 2's complement: N/A
- 16-bit 1's complement: N/A
- 16-bit Sign and Magnitude: N/A
-
16-bit Unsigned Representation:
- Dynamic range: . Since , it is fully representable.
- Calculation:
- Bit string:
1111 1111 1111 1110
Problem 4: Value
-
Range Verification:
- Signed symmetric range (1's complement and Sign-Magnitude): .
-
N/A for 1's complement and Sign-and-Magnitude.
- Unsigned range: .
-
N/A for unsigned representation.
-
16-bit 2's Complement Representation:
- 2's complement range is . is representable as the unique asymmetric minimum.
- Derivation:
- Bit string:
1000 0000 0000 0000
◇Problem Set 2: 16-Bit Binary to Decimal Decoding
Instructions: Given the 16-bit binary pattern, calculate the decimal equivalent value under each specified integer representation scheme.
Summary Solution Table
| Binary Bit Pattern | 16-bit 2's Complement | 16-bit 1's Complement | 16-bit Sign and Magnitude | 16-bit Unsigned Representation |
|---|---|---|---|---|
5.) 0000 1111 0000 1000 | +3848 | +3848 | +3848 | 3848 |
6.) 1111 0000 1111 0001 | -3855 | -3854 | -28913 | 61681 |
Step-by-Step Derivations
Problem 5: Binary String ()
-
MSB Inspection:
When , all signed formats share identical numeric interpretation with unsigned binary. -
Positional Expansion:
Hexadecimal verification:
-
Results:
- 16-bit 2's complement:
+3848 - 16-bit 1's complement:
+3848 - 16-bit Sign and Magnitude:
+3848 - 16-bit Unsigned:
3848
- 16-bit 2's complement:
Problem 6: Binary String ()
- MSB Inspection:
-
16-bit Unsigned Interpretation:
-
16-bit Sign and Magnitude Interpretation:
- Sign bit .
- Lower 15 bits ():
111 0000 1111 0001(). - Absolute magnitude:
- Decimal Value:
-
16-bit 1's Complement Interpretation:
- Sign bit .
- Bitwise inversion to recover magnitude:
- Absolute magnitude:
- Decimal Value:
-
16-bit 2's Complement Interpretation:
- Method A (Negation Rule):
- Method B (Direct Weighted Positional Sum):
- Method C (Unsigned Modulo Shift):
- Decimal Value:
- Method A (Negation Rule):
◇Key Takeaways & Reference Matrix
Encoding Schemes at a Glance ( bits)
| Scheme | Representation of Positives | Representation of Negatives | Zero Representation | Range () |
|---|---|---|---|---|
| Unsigned | Natural binary | N/A | Single: 0000...0000 | |
| Sign-Magnitude | MSB = 0, lower bits = magnitude | MSB = 1, lower bits = magnitude | Dual: +0 (00..00), -0 (10..00) | |
| 1's Complement | Natural binary | Bitwise NOT () | Dual: +0 (00..00), -0 (11..11) | |
| 2's Complement | Natural binary | Bitwise NOT () | Single: 0000...0000 | |
| Biased () | Value in binary | Value in binary | Single: 1000...0000 |
Hardware Implications
- Why 2's Complement Dominates:
- A single representation for zero eliminates special-case testing logic in conditional branch instructions (
BEQ,BNE). - Standard binary adder hardware computes both addition and subtraction () without needing separate subtractor circuits.
- Continuous modular mapping () allows natural wrap-around arithmetic.
- A single representation for zero eliminates special-case testing logic in conditional branch instructions (
◇References & Navigation
- Related Notes: ◇Integer Representation & Fixed-Point Arithmetic