Until now, we have discussed only positive numbers. These numbers were called "unsigned 8-bit integers". In an 8-bit byte, we can represent a set of 256 positive numbers in the range 010-25510. However, in many operations it is necessary to also have negative numbers. For this purpose, we introduce "signed 8-bit integers". Since we are limited to 8-bit representation, we remain also limited to a total of 256 numbers. However, half of them will be negative (-12810 through -110) and half will be positive (010 through 12810).
The representation of signed (positive and negative) numbers in the computer is done through the so-called 8-bit 2's complement representation. In this representation, the 8th bit indicates the sign of the number (0 = +, 1 = -).
The signed binary numbers must conform to the obvious laws of signed arithmetic. For example, in signed decimal arithmetic, -310 + 310 = 010. When performing signed binary arithmetic, the same cancellation law must be verified. This is assured when constructing the 2's complement negative binary numbers through the following rule:
To find the negative of a number in 8-bit 2's complement representation, simply subtract the number from zero, i.e. -X = 0 - X using 8-bit binary arithmetic.
Example 1: Use the above rule to represent in 8-bit 2's complement the number -310
Solution: Subtract the 8-bit binary representation of 310 from the 8-bit binary representation of 010 using 8-bit arithmetic (8-bit arithmetic implies that you can liberally take from, or carry into the 9th bit, since only the first 8 bits count!).
BINARY DECIMAL 00000000 - 010 - 00000011 310 11111101 -310
Note that, in this operation, a 1 was liberally borrowed from the 9th bit and used in the subtraction!Verification We have establish that -310 = 111111012. Verify that -310 + 310 = 010 using 8-bit arithmetic. BINARY DECIMAL 11111101 - -310 - 00000011 310 00000000 010Note that, in this operation, a carry of 1 was liberally lost in the 9th bit!
Example 2: Given the binary number 00110101, find it's 2's complement.
Verification: 01110101 + 10001011 = (1)00000000. Since the 9th bit is irrelevant, the answer is actually 00000000, as expected
The rule outlined above can be applied to both binary and hex numbers.
Example 3: Given the hex number 6A, find its 8-bit 2's complement.
Solution: Subtract the number from 0016 using 8-bit arithmetic:
Verification: 6A16 + 9616 = (1)00. Since the 9th binary bit is irrelevant, the answer is actually 0016, as expected