Uploaded by Viknesh Hrithik

Computer Architecture

advertisement
Modular number systems and
the 2s complement system
The 2s complement method
The 2s complement is an important method for binary addition and
subtraction and is more efficient than the other methods.
Hence, most systems implement this technique to perform binary
operations.
The working of the 2s complement method can be better understood
by a graphical representation based on modular arithmetic.
Modular Number Systems
Modular arithmetic is a system of arithmetic for integers, where numbers "wrap
around" when reaching a certain value, called the modulus.
The modern approach to modular arithmetic was developed by the
German mathematician Gauss.
A familiar use of modular arithmetic is in the 12-hour clock, in which the day is
divided into two 12-hour periods
If the time is 8:00 now, then 8 hours later it will be 4:00. Simple addition would
result in 8 + 8 = 16, but clocks "wrap around" every 12 hours.
Because the hour number starts over after it reaches 12, this is
arithmetic modulo 12
Circular representation
of integers mod N
A helpful graphical device for the
description of addition of
A helpful graphical device for the description of addition of unsigned integers mod N is a circle with the values 0 through N − 1
integers mod N is a
marked along its perimeter, unsigned
as shown in Figure
circle with the values 0 through N
− 1 marked along its perimeter, as
shown in the figure.
Addition Modulo 16 (4 bit numbers)
§ Consider the case N = 16
§ The decimal values 0 through 15 are represented by their 4bit binary values 0000 through 1111 around the outside of the
circle
§ Say we want to check the result of the operation (7+5)%16
§ To perform this operation graphically, locate 7 (0111) on
the outside of the circle and then move 5 units in the
clockwise direction to arrive at the answer 12 (1100).
§ Similarly, (9 + 14) mod 16 = 7; this is modeled on the circle by
locating 9 (1001) and moving 14 units in the clockwise direction
past the zero position to arrive at the answer 7 (0111).
§ This graphical technique works for the computation
of
(a + b) mod 16 for any unsigned integers a and b; that
is, to perform addition, locate a and move b units in the clockwise
direction to arrive at (a + b) mod 16.
2s complement method
Now consider a different interpretation of the mod 16 circle
We will reinterpret the binary vectors outside the circle to represent the signed integers from −8
through +7 in the 2’s-complement representation as shown inside the circle.
 Let us apply the mod 16 addition technique to the
example of adding +7 to −3.
 The 2’s-complement representation for these numbers
is 0111 and 1101, respectively.
 Here assume the second binary number 1101, to be
an unsigned number, which gives us 13.
 To add these numbers, locate 0111 on the circle,
then move 1101 (13) steps in the clockwise direction to
arrive at 0100, which yields the correct answer of +4.
 Note that the 2’s-complement representation of −3 is
interpreted as an unsigned value for the number of
steps to move.
 The circular representation of modular arithmetic system can be
used as way to interpret the working of binary addition and
subtraction using 2s complement method graphically.
Modular arithmetic is also part of the reason for discarding the
carry-out bit(under no overflow condition),since in modular
arithmetic for the number 16, the value next to 1111 is taken as
0000 and not the next binary number 10000.
Download