|

楼主 |
发表于 2008-9-8 23:42:23
|
显示全部楼层
2's Complement DivisionTwo's complement division is repeated 2's complement subtraction. The 2's complement of the divisor is calculated, then added to the dividend. For the next subtraction cycle, the quotient replaces the dividend. This repeats until the quotient is too small for subtraction or is zero, then it becomes the remainder. The final answer is the total of subtraction cycles plus the remainder.
For example,
7 ÷ 3 = 2 remainder 1 | | 0000 0111 | = | +7 | | 0000 0100 | = | +4 | + 1111 1101 | = | -3 | + 1111 1101 | = | -3 | 0000 0100 | = | +4 | 0000 0001 | = | +1 (remainder) |
Sign ExtensionTo extend a signed integer from 8 bits to 16 bits or from 16 bits to 32 bits, append additional bits on the left side of the number. Fill each extra bit with the value of the smaller number's most significant bit (the sign bit).
For example,
Signed Integer | 8-bit Representation | 16-bit Representation | | -1 | 1111 1111 | 1111 1111 1111 1111 | +1 | 0000 0001 | 0000 0000 0000 0001 |
Other Representations of Signed IntegersSign-Magnitude Representation Another method of representing negative numbers is sign-magnitude. Sign-magnitude representation also uses the most significant bit of the number to indicate the sign. A negative number is the 7-bit binary representation of the positive number with the most significant bit set to one. The drawbacks to using this method for arithmetic computation are that a different set of rules are required and that zero can have two representations (+0, 0000 0000 and -0, 1000 0000). Offset Binary Representation A third method for representing signed numbers is offset binary. Begin calculating a offset binary code by assigning half of the largest possible number as the zero value. A positive integer is the absolute value added to the zero number and a negative integer is subtracted. Offset binary is popular in A/D and D/A conversions, but it is still awkward for arithmetic computation. For example,
Largest value for 8-bit integer = 28 = 256 | Offset binary zero value = 256 ÷ 2 = 128(decimal) = 1000 0000(binary) |
1000 0000(offset binary 0) + 0001 0110(binary 22) = 1001 0110(offset binary +22) | 1000 0000(offset binary 0) - 0000 0111(binary 7) = 0111 1001(offset binary -7) |
Signed Integer | Sign Magnitude | Offset Binary | | +5 | 0000 0101 | 1000 0101 | +4 | 0000 0100 | 1000 0100 | +3 | 0000 0011 | 1000 0011 | +2 | 0000 0010 | 1000 0010 | +1 | 0000 0001 | 1000 0001 | 0 | 0000 0000
1000 0000 | 1000 0000 | -1 | 1000 0001 | 0111 1111 | -2 | 1000 0010 | 0111 1110 | -3 | 1000 0011 | 0111 1101 | -4 | 1000 0100 | 0111 1100 | -5 | 1000 0101 | 0111 1011 |
NotesOther Complements 1's Complement = NOT(n) = 1111 1111 - n 9's Complement = 9999 9999 - n 10's Complement = (9999 9999 - n) + 1 Binary Arithmetic Addition Subtraction Multiplication Division |
|