6.Representation of data in the Computer, Computer Arithmetic |
|
6.1 Negative Numbers, Complement on Two |
In the representation of the complement of two the positive numbers are traversed first, then the negative numbers in reversed order. 0000 = 0 1000 = - 8 0001 = 1 1001 = - 7 0010 = 2 1010 = - 6 0011 = 3 1011 = - 5 0100 = 4 1100 = - 4 0101 = 5 1101 = - 3 0110 = 6 1110 = - 2 0111 = 7 1111 = - 1 On the complement of two, the first number stands for the algebraic sign. Value of a positive number W = ∑ i=0,n-1 (bi* 2(n-1-i)) Example an integer-number shall be displayed as an 8 bit number to the base of 2 W(000011012 ) = 0*27 +..+ 0*24 + 1*23 + 1*22 + 0*21 + 1*20 = 8 + 4 + 1 = 1310 Value of a negatve Number W = - (2n - ∑i=0,n-1 (bi* 2(n-1-i))) Building the difference of two integers decimal dual 17 00010001 +(-14) 11110010 = 3 00000011 Complement on two on the number-circle ![]() Complement on two (Definition) The bit-sequence zn zn-1 zn-2 . . . z1 z0 represents the binary number - zn * 2n + zn-1 * 2(n-1) + zn-2 * 2(n-2) + . . . + z1 * 21 + z0 Complement on two for n=3 For n = 3 follows: 1000 = - 8 1100 = - 4 0000 = 0 0100 = 4 1001 = - 7 1101 = - 3 0001 = 1 0101 = 5 1010 = - 6 1110 = - 2 0010 = 2 0110 = 6 1011 = - 5 1111 = - 1 0011 = 3 0111 = 7 Negation on the Complement on Two I you add a number to itscomplement, the result is 111 ... 1111 111 .... 1111 = - 2n + 2(n-1) + ... + 21 + 1 = - 2n + ( 2n - 1) = - 1 A number plus its complement results into the representation of -1 So, negating a number is done by adding 1 to its complement. Basic Arithmetic Operations for the Complement on Two Addition: Use of the same hardware as on the signless numbers S=A+B; Ci=Carry-In = 0 ![]() -5 + 6 = 1 in representation on the complement on two : 1011 + 0110 = 0001 (watch out when going out of the range) Negation 5 in complement on two : 0101 -5 in complement on two : 1011 complement all bits, then add 1 Subtraction: Addition with bit-inversion of the subtrahend and Carry-In on the LSB D=A-B, Ci=Carry-In=1 ![]() negate the second operand, then add Complement on two-Addition/Subtraction und Overflow Overflow = The representable number-range is exceeded Overflow when adding numbers in complement on two: Examples: -3 + (-6) = -9 1101 + 1010 = 1 0111 = +7 5 + 6 = 11 0101 + 0110 = 1011 = -5 A sure symptom for an overflow: Summands of the same sign ≠ Sign of the sum => Carry-In in sign-position ≠ Carry-Out of sign-position Overflow at subtraction on numbers in complement on two: Example: -3 - (+6) = -9 =>1101 - 0110 => 1101 + 1001 + 0001 = 1 0111 = +7 A sure symptom for an overflow: Minuend & complem.subtrahend same sign ≠ sign of the difference => Carry-In in sign-position ≠ Carry-Out of sign-position <back> |
6.2 Floating-Point Numbers |
|
6.3 Multiplication Multiplication of binary-numbers The multiplication of binary-numbers can be reduced to addition and shift-operations. The binary-representation of X is shifted each time for one digit to the left. If the corresponding position of Y equaled 0, it's annullated, elseway added. To realize the multiplication with a computer, there exists the so called Barrel-Shifter. It consists mainly of AND-cirquits and 1-bit adding-cirquits. The bitwise multiplication is the same as the logical and-operation. If X and Y are the input-registers with the bit-digits X(n-1),....,X(0) bzw. Y(n-1),....,Y(0) , a gate is to be built where every crossing-point X(i) with Y(i) is linked through an AND-cirquit. By the adding-cirquits the columns are added. The carry-bit is carried through row by row. An overflow in a row will be added to the next column. For the result of a multiplication the register should be double as broad as the input-register. The 1-bit ALU To construct a multiple-bit-ALU, it is enough to put several 1-bit-ALUs in a row. For the arithmetical operations, a carry from one to the next bit-position has to be considered. So that for each 1-bit-ALU an extra carry-in and carry-out has to be built. To implement 8 several operations, a 1-bit-ALU with 6 inputs has to be realized: 3 inputs M, S0 and S1, a carry-input Ci, and also the inputs for Xi and Yi. But only two outputs are needed. Si for the result of the operation and C(i+1) for the new carry. The logical cirquit-plan is shown here:
|
<back> |