- Published on
KembaraXtra-Computer Science-Signed Numbers
1. Introduction to Signed Numbers
1. Introduction to Signed Numbers
- Need for Signed Numbers: Computers represent data as 0s and 1s. A convention is needed to represent negative numbers since "-" isn't a binary digit.
- Signed Number Definition: A sequence of bits used to represent both positive and negative numbers. The interpretation depends on the bits' values and the chosen system.
- Concept: Assign one bit (usually the most significant bit) to represent the sign. 0 for positive, 1 for negative. Remaining bits represent the magnitude (absolute value).
- Drawback: Requires extra complexity in hardware design (e.g., adder circuits need modification) to handle the sign bit separately.
- Definition: The two's complement of a number represents the negative of that number.
- Calculation:
- Flip the bits: Replace every 0 with a 1 and every 1 with a 0 (also known as the one's complement).
- Add 1: Add 1 to the result of step 1.
- Example:
- 5 (0101 in 4-bit binary)
- Flip bits: 1010
- Add 1: 1011. Therefore, -5 is 1011 in two's complement.
- Reversing the Process: Taking the two's complement of a negative number (in two's complement form) results in the original positive number. two_comp(two_comp(x)) = x
- Simplified Arithmetic: Addition and subtraction operations work directly without needing special handling for negative numbers. Standard adder circuits can be used.
- Example: 7 + (-3)
- 7 = 0111
- -3 = 1101 (two's complement)
- 0111 + 1101 = 10100
- Ignore the carry-out bit, the result is 0100, which is 4.
- Dual Meaning:
- Notation: A system for representing positive and negative integers.
- Operation: A process to negate an integer already in two's complement format.
- Key Concept: The most significant bit's place value is the negative of its usual positive value. All other place values are positive.
- Example (4-bit):
- Bit positions (right to left): 20, 21, 22, 23
- Place values: 1, 2, 4, -8
- Example: -3 (1101)
- (1 * -8) + (1 * 4) + (0 * 2) + (1 * 1) = -8 + 4 + 0 + 1 = -3
- 4-bit Example:
- Maximum positive: 7 (0111)
- Minimum negative: -8 (1000)
- All possible values illustrated in Table 5-3 of the source material.
- Generalization for n-bit signed number:
- Maximum value: (2n-1) - 1
- Minimum value: -(2n-1)
- Count of unique values: 2n
- Example (8-bit):
- Maximum value: 127
- Minimum value: -128
- Count of unique values: 256
0 Comments