Signed Numbers and Binary Representations

Introduction to Signed Number Representation

  • Computers operate using binary digits (00 and 11), whereas human calculation naturally involves positive and negative numbers such as +45+45, −10-10, +127+127, and −80-80.
  • Signed Number Representation provides a method for computers to represent negative numerical values using only binary digits.

Unsigned vs. Signed Numbers

  • Binary registers of a fixed size (e.g., 8-bit) can be interpreted as either unsigned or signed.
  • Unsigned Numbers (8-bit register):
    • These represent only positive values starting from zero.
    • 00000000=000000000 = 0
    • 00000001=100000001 = 1
    • 11111111=25511111111 = 255
    • Range: 00 to 255255.
  • Signed Numbers (8-bit register):
    • The binary digits represent both the sign and the magnitude of the number.
    • The Most Significant Bit (MSB), or the leftmost bit, becomes the dedicated sign bit.
    • Sign Bit Convention:
      • 0=Positive0 = \text{Positive}
      • 1=Negative1 = \text{Negative}
    • Example Comparisons:
      • 0110010001100100 represents +100+100.
      • 1110010011100100 represents a negative number.
    • Range: −128-128 to +127+127.

The Mechanics of Signed Binary

  • Signed binary numbers consist of two distinct components:
    • Sign: Indicated by the MSB to show if the value is positive or negative.
    • Magnitude: The actual numerical value of the number.
  • Bit patterns for identifying sign:
    • 0xxxxxxx=Positive0xxxxxxx = \text{Positive}
    • 1xxxxxxx=Negative1xxxxxxx = \text{Negative}
  • Identification Drill:
    • a) 0011011100110111: MSB is 00, hence Positive.
    • b) 1100110111001101: MSB is 11, hence Negative.
    • c) 1000000010000000: MSB is 11, hence Negative.
    • d) 0111111101111111: MSB is 00, hence Positive.

Methods for Representing Negative Numbers

  • There are three primary mathematical models for representing signed numbers in computing:
    1. Sign-Magnitude
    2. One's Complement
    3. Two's Complement: This is the standard representation utilized in modern processors, including the 80868086.

Sign-Magnitude Representation

  • In this method, the leftmost bit is strictly the sign bit, and the remaining 7 bits of an 8-bit register represent the magnitude.
  • Structural Example (±25\pm 25):
    • +25+25 is expressed as 0001100100011001.
    • −25-25 is expressed as 1001100110011001.
    • The lone difference between the positive and negative version is the state of the sign bit.
  • Decimal to 8-bit Sign-Magnitude Exercises:
    • −39-39 becomes 1010011110100111.
    • −15-15 becomes 1000111110001111.
    • −33-33 becomes 1010000110100001.
  • Sign-Magnitude to Decimal Exercises:
    • 10010101→−2110010101 \rightarrow -21
    • 00001111→+1500001111 \rightarrow +15
    • 11000001→−6511000001 \rightarrow -65

One's Complement Representation

  • Inversion Rule: To find the one's complement of a binary number, every bit must be inverted (change all 11's to 00's and all 00's to 11's).
  • Representation Logic:
    • Positive numbers are represented identically to positive sign-magnitude numbers.
    • Negative numbers are the one's complement of their corresponding positive number.
  • Digital Logic Application:
    • The simplest hardware implementation for obtaining a one's complement is through the use of parallel inverters (NOT circuits).
  • Conversion Examples (+x+x to −x-x):
    • Convert −25-25:
      • +25=00011001+25 = 00011001
      • Invert: 1110011011100110 (−25-25 in 1's complement).
    • Convert −23-23:
      • +23=00010111+23 = 00010111
      • Invert: 1110100011101000 (−23-23 in 1's complement).
    • Convert −13-13:
      • Binary of 13=0000110113 = 00001101
      • Invert: 1111001011110010 (−13-13 in 1's complement).
    • Convert −45-45:
      • Binary of 45=0010110145 = 00101101
      • Invert: 1101001011010010 (−45-45 in 1's complement).
    • Convert −100-100:
      • Binary of 100=01100100100 = 01100100
      • Invert: 1001101110011011 (−100-100 in 1's complement).
    • Convert −127-127:
      • Binary of 127=01111111127 = 01111111
      • Invert: 1000000010000000 (−127-127 in 1's complement).
  • Converting One's Complement to Decimal:
    1. If the MSB is 11, the number is negative.
    2. Invert all bits.
    3. Convert the resulting binary to decimal.
    4. Apply the negative sign.
  • Practice Exercises (1's Complement to Decimal):
    • 11110010→Invert: 00001101→13→Answer: −1311110010 \rightarrow \text{Invert: } 00001101 \rightarrow 13 \rightarrow \text{Answer: } -13
    • 10100101→Invert: 01011010→90→Answer: −9010100101 \rightarrow \text{Invert: } 01011010 \rightarrow 90 \rightarrow \text{Answer: } -90
    • 11110110→Answer: −911110110 \rightarrow \text{Answer: } -9
    • 11100010→Answer: −2911100010 \rightarrow \text{Answer: } -29
    • 10101010→Answer: −8510101010 \rightarrow \text{Answer: } -85
    • 11001111→Answer: −4811001111 \rightarrow \text{Answer: } -48
    • 10000000→Answer: −12710000000 \rightarrow \text{Answer: } -127
  • Disadvantages and Abandonment:
    • One's complement is rarely used because it features two representations for zero:
      1. +0=00000000+0 = 00000000
      2. −0=11111111-0 = 11111111
    • This redundancy complicates arithmetic logic and value comparisons.

Two's Complement Representation

  • Two's complement is the standard for modern computing systems.
  • Conversion Rules:
    • Step 1: Write the number in positive binary.
    • Step 2: Invert all bits (obtaining the 1's complement).
    • Step 3: Add 11 to the Least Significant Bit (LSB).
  • Conversion Examples (xx to −x-x):
    • Convert −25-25:
      • +25=00011001+25 = 00011001
      • Invert: 1110011011100110
      • Add 11: 1110011111100111
    • Convert −39-39:
      • +39=00100111+39 = 00100111
      • Invert: 1101100011011000
      • Add 11: 1101100111011001
    • Convert −50-50:
      • +50=00110010+50 = 00110010
      • Invert: 1100110111001101
      • Add 11: 1100111011001110
    • Convert −1-1:
      • +1=00000001+1 = 00000001
      • Invert: 1111111011111110
      • Add 11: 1111111111111111 (often written as FFhFFh in hex).
  • Special Case -128:
    • In an 8-bit system, the number +128+128 cannot be represented because the range for positive numbers ends at +127+127.
    • However, the bit pattern 1000000010000000 is the standard representation for −128-128 in two's complement.
  • Converting Two's Complement to Decimal:
    1. Identify that MSB is 11 (Negative).
    2. Invert all bits.
    3. Add 11 to the result.
    4. Convert to decimal and apply the negative sign.
  • Practice Exercises (2's Complement to Decimal):
    • Given 1110011111100111:
      • Invert: 0001100000011000
      • Add 11: 0001100100011001 (Magnitude 2525)
      • Answer: −25-25
    • Given 1111011011110110:
      • Invert: 0000100100001001
      • Add 11: 0000101000001010 (Magnitude 1010)
      • Answer: −10-10
    • Given 1111111111111111:
      • Invert: 0000000000000000
      • Add 11: 0000000100000001 (Magnitude 11)
      • Answer: −1-1

Summary and Cross-System Comparison

  • Positive Numbers: For all three systems, the sign bit is 00.

  • Negative Numbers: The sign bit is always 11, but the remaining bits vary:

    • Sign-Magnitude: Leftmost bit is 11.
    • 1's Complement: Invert bits of the positive number.
    • 2's Complement: Invert bits of the positive number and add 11.
  • Comprehensive Example Comparison:

    • Case A: 0001011000010110
      • This represents +22+22.
      • The representation is the same in Sign-Magnitude, 1's Complement, and 2's Complement.
    • Case B: 1001000110010001
      • Sign-Magnitude value: −17-17
      • 1's Complement value: −110-110
      • 2's Complement value: −111-111