PROJECTENGRAM

DATA REPRESENTATION - INTEGERS

4.0 Data Representation - Integers

Tags: #◇Computer Science #◇CCICOMP #◇Problem Solving #◇M2


◇Overview

Data representation involves encoding information into binary form so it can be reliably transported and processed by computer circuitry. Any numeric representation format balances size, range, accuracy, ease of manipulation, and standardization. Integers can be represented as unsigned (only non-negative values) or signed (capable of representing both positive and negative values). While various encoding schemes exist for signed integers, modern CPUs almost universally use the 2's complement scheme. Since data types use fixed-width bit strings, calculations that exceed the format's capacity result in overflow, producing mathematically illogical values.

◇Important Formulas

Unsigned Integers Value Evaluation: An nn-bit unsigned integer bn−1…b1b0b_{n-1}\dots b_1b_0 has the decimal value:

Value=∑i=0n−1bi2i\text{Value} = \sum_{i=0}^{n-1} b_i 2^i Range: 00 to 2n−12^n - 1. For example, an 88-bit unsigned integer ranges from 00 to 255255. Zero Extension: To expand the width of an unsigned integer, simply pad the left side (most significant bits) with 00s.

Signed Integers

Signed integers allocate the Most Significant Bit (MSB) as the sign bit: 00 for positive, 11 for negative. Sign-and-Magnitude: The MSB is the sign, and the remaining bits represent the absolute magnitude of the number in standard binary. 1's Complement: To represent a negative number, start with the positive unsigned binary value and invert every bit (0→10 \to 1, 1→01 \to 0). 2's Complement: To represent a negative number, invert every bit of the positive unsigned binary value and add 11.
Range: −(2n−1)-(2^{n-1}) to 2n−1−12^{n-1} - 1. E.g., for 88-bit: −128-128 to 127127.
Only uses one representation of 00 (unlike 1's complement and sign-and-magnitude). Sign Extension: To expand the width of a signed integer, replicate the sign bit to the left (e.g., 1011→111110111011 \to 11111011 for negatives, 0101→000001010101 \to 00000101 for positives).

◇Worked Examples

1. Converting to 2's Complement

Represent −2510-25_{10} as an 88-bit signed integer in 2's complement.

  1. Determine absolute value in binary: 2510=00011001225_{10} = 00011001_2 (with leading zeros to make 88 bits).
  2. Invert bits (1's complement): 11100110211100110_2.
  3. Add 11: 111001102+1=11100111211100110_2 + 1 = 11100111_2.
    Result: 11100111211100111_2.

2. Converting from 2's Complement

Find the decimal equivalent of the 88-bit 2's complement number 11100111211100111_2.

  1. Check MSB: 11 means negative.
  2. Invert bits: 00011000200011000_2.
  3. Add 11: 000110002+1=00011001200011000_2 + 1 = 00011001_2.
  4. Convert to decimal: 000110012=251000011001_2 = 25_{10}.
  5. Apply sign: −2510-25_{10}.

3. Overflow Condition

Add the 88-bit signed values 901090_{10} and 401040_{10}. 9010=01011010290_{10} = 01011010_2 4010=00101000240_{10} = 00101000_2 Addition: 010110102+001010002=10000010201011010_2 + 00101000_2 = 10000010_2
Notice the MSB is now 11. In an 88-bit signed 2's complement system, 10000010210000010_2 is interpreted as −12610-126_{10}. Because 90+40=13090 + 40 = 130, which exceeds the maximum 88-bit positive range of 127127, the magnitude overflowed into the sign bit, causing an illogical negative result.

◇References & Navigation

CONFIRMATION // 理解度の確認

ACTIVE RECALL VERIFICATION

Select an answer to verify conceptual comprehension and reveal the technical rationale.

Q1

Which of the following best describes data representation in the context of computer circuitry?

Q2

What distinguishes unsigned integers from signed integers?

Q3

Which encoding scheme is almost universally used by modern CPUs for signed integers?

Q4

What happens when a calculation exceeds the fixed-width capacity of an integer format?

Q5

How is zero extension performed on an unsigned integer?

Q6

In a signed integer representation, what does a Most Significant Bit (MSB) of 1 indicate?

Q7

How do you convert a positive binary number to its 1's complement negative equivalent?

Q8

What is the formula for the maximum range of an n-bit unsigned integer?

Q9

What is a key advantage of 2's complement over sign-and-magnitude representation?

Q10

How is sign extension performed on a negative 2's complement signed integer?

Data Representation - Integers | PROJECT ENGRAM