Signed Numbers and Binary Representations
Introduction to Signed Number Representation
- Computers operate using binary digits ( and ), whereas human calculation naturally involves positive and negative numbers such as , , , and .
- 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.
- Range: to .
- 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:
- Example Comparisons:
- represents .
- represents a negative number.
- Range: to .
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:
- Identification Drill:
- a) : MSB is , hence Positive.
- b) : MSB is , hence Negative.
- c) : MSB is , hence Negative.
- d) : MSB is , hence Positive.
Methods for Representing Negative Numbers
- There are three primary mathematical models for representing signed numbers in computing:
- Sign-Magnitude
- One's Complement
- Two's Complement: This is the standard representation utilized in modern processors, including the .
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 ():
- is expressed as .
- is expressed as .
- The lone difference between the positive and negative version is the state of the sign bit.
- Decimal to 8-bit Sign-Magnitude Exercises:
- becomes .
- becomes .
- becomes .
- Sign-Magnitude to Decimal Exercises:
One's Complement Representation
- Inversion Rule: To find the one's complement of a binary number, every bit must be inverted (change all 's to 's and all 's to '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 ( to ):
- Convert :
- Invert: ( in 1's complement).
- Convert :
- Invert: ( in 1's complement).
- Convert :
- Binary of
- Invert: ( in 1's complement).
- Convert :
- Binary of
- Invert: ( in 1's complement).
- Convert :
- Binary of
- Invert: ( in 1's complement).
- Convert :
- Binary of
- Invert: ( in 1's complement).
- Convert :
- Converting One's Complement to Decimal:
- If the MSB is , the number is negative.
- Invert all bits.
- Convert the resulting binary to decimal.
- Apply the negative sign.
- Practice Exercises (1's Complement to Decimal):
- Disadvantages and Abandonment:
- One's complement is rarely used because it features two representations for zero:
- This redundancy complicates arithmetic logic and value comparisons.
- One's complement is rarely used because it features two representations for zero:
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 to the Least Significant Bit (LSB).
- Conversion Examples ( to ):
- Convert :
- Invert:
- Add :
- Convert :
- Invert:
- Add :
- Convert :
- Invert:
- Add :
- Convert :
- Invert:
- Add : (often written as in hex).
- Convert :
- Special Case -128:
- In an 8-bit system, the number cannot be represented because the range for positive numbers ends at .
- However, the bit pattern is the standard representation for in two's complement.
- Converting Two's Complement to Decimal:
- Identify that MSB is (Negative).
- Invert all bits.
- Add to the result.
- Convert to decimal and apply the negative sign.
- Practice Exercises (2's Complement to Decimal):
- Given :
- Invert:
- Add : (Magnitude )
- Answer:
- Given :
- Invert:
- Add : (Magnitude )
- Answer:
- Given :
- Invert:
- Add : (Magnitude )
- Answer:
- Given :
Summary and Cross-System Comparison
Positive Numbers: For all three systems, the sign bit is .
Negative Numbers: The sign bit is always , but the remaining bits vary:
- Sign-Magnitude: Leftmost bit is .
- 1's Complement: Invert bits of the positive number.
- 2's Complement: Invert bits of the positive number and add .
Comprehensive Example Comparison:
- Case A:
- This represents .
- The representation is the same in Sign-Magnitude, 1's Complement, and 2's Complement.
- Case B:
- Sign-Magnitude value:
- 1's Complement value:
- 2's Complement value:
- Case A: