Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.

Similar presentations


Presentation on theme: "Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text."— Presentation transcript:

1 Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text

2 Review Previously we briefly looked at binary addition and subtraction. For this lecture we will consider 4-bit binary numbers since they are easy to write on the board.

3 Signed Integer If we wish to represent signed integers, a straightforward way to represent them on a computer is to use one bit for the sign (0 for positive and 1 for negative) and allow the remaining three bits to represent the value. Using four bits we have 16 possible values. Positive numbers follow below. Notice that the first bit is zero, indicating that these are positive integers. 0000b = 0d 0001b = 1d 0010b = 2d 0011b = 3d 0100b = 4d 0101b = 5d 0110b = 6d 0111b = 7d 1000b = -0d 1001b = -1d 1010b = -2d 1011b = -3d 1100b = -4d 1101b = -5d 1110b = -6d 1111b = -7d Negative numbers: Notice that we have a negative zero.

4 Addition Let's investigate addition with these values. Addition with positive integers works: 0011b = 3d +0100b = 4d -------------- 0111b = 7d But what about addition of positive and negative integers? Notice that this is the same as subtraction. 0010b = 2d +1101b = -5d -------------- 1111b != -3d

5 Addition Contd. It is going to take lots of effort to compute the difference between two numbers. We need a different representation to perform such an addition. Let's look at one's complement representation of binary numbers. In one's complement, positive binary numbers are represented as above including the sign bit. To represent negative binary numbers in one's complement, we simply perform a bit flip. Let's examine how this works: 0000b = 0d1111 = -0d (this might be a problem) 0001b = 1d1110 = -1d 0010b = 2d1101 = -2d 0011b = 3d1100 = -3d 0100b = 4d1011 = -4d 0101b = 5d1010 = -5d 0110b = 6d1001 = -6d 0111b = 7d1000 = -7d

6 2’s Compliment Let's see if we can perform binary additions between positive and negative numbers as follows: 1101b = -2d +0101b = 5d ------------------ 0010b != 3d Notice that we are off by one from our correct answer. Let's try modifying our representation. Two's complement binary numbers are slightly different from one's complement numbers. To find the value of our negative numbers, we perform a bit flip and add one.

7 2’s Compliment 0000b = 0d 0001b = 1d 1111 = -1d 0010b = 2d 1110 = -2d 0011b = 3d 1101 = -3d 0100b = 4d 1100 = -4d 0101b = 5d 1011 = -5d 0110b = 6d 1010 = -6d 0111b = 7d 1001 = -7d 1000 = -8d Notice that we could represent 1000 as 8, but it might be better to represent it as -8. Why? Notice that if we perform binary additions between positive and negative numbers, they now work.

8 2’s Compliment 1110b = -2d +0101b = 5d ------------- 0011b = 3d Additionally, notice that if we add numbers that should sum to zero, it works as well: 1101b = -3d +0011b = 3d ------------- 0000b = 0d Next time we will look at binary representations for floating point numbers.


Download ppt "Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text."

Similar presentations


Ads by Google