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 Patterson and Hennessy Text.

Similar presentations


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

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

2 Review Last time we looked at several different representations of signed integers. We looked at signed binary numbers, where we used a leading zero or one to represent sign. We also looked at one's complement and two's complement numbers. This time – Review two's complement for the homework assignment. – Floating Point Representation

3 Review 2’s Compliment Two's complement numbers are used on most CPUs to represent signed integer values. Positive values are converted to negative values from regular sign and magnitudebinary representation using the following method: 1.bit flip 2.add one to the result Such values are converted back from negative to positive by undoing the operationsabove: 1.subtract one from the two's complement representation of the negative number 2.bit flip the result

4 Examples Using 5 bit binary numbers we may represent 10 as follows in signed magnitude representation: 01010 b = 10d Notice that in the representation above we have four bits representing the value and one bit (the leading zero) representing the sign (0 for positive and 1 for negative). Performing a bit flip on 10d yields the following result: 10101b Adding one yields the two's complement representation: 10110b = -10d (two's complement) Notice that in the example above there is a leading one representing that the number is negative. All one's complement, two's complement, and signed magnitude binary numbers have aleading zero or one to represent the value as positive or negative respectively.

5 Five bit 2’s Compliment Numbers 00000b = 0d 00001b = 1d11111b = -1d 00010b = 2d11110b = -2d 00011b = 3d11101b = -3d 00100b = 4d11100b = -4d 00101b = 5d11011b = -5d 00110b = 6d11010b = -6d 00111b = 7d11001b = -7d 01000b = 8d11000b = -8d 01001b = 9d10111b = -9d 01010b = 10d10110b = -10d 01011b = 11d10101b = -11d 01100b = 12d10100b = -12d 01101b = 13d10011b = -13d 01110b = 14d10010b = -14d 01111b = 15d10001b = -15d 10000b = -16d

6 Examples Examples of adding and subtracting these values follow below: 01010b = 10d +10110 = -10d -------------------------- 00000b = 0d Subtraction or performing the operation a - b, can be represented as a + (-b).Take 9 - 3 as an example. We first convert 3 to -3 and add -3 to 9 as follows: 01001b = 9d +11101 = -3d -------------------------- 00110b = 6d

7 Examples Subtracting a negative number from another negative number is equally easy. We simply subtract one from the two's complement representation of the negative number and perform a bit flip. For example if we take -8 - (-4), the result should be -4. But to perform thisoperation as an addition, we need to convert -4 to +4. 11100b is the two's complement representation of -4. 11100b - 1b = 11011b Bit flipping 11011b yields 00100b = 4d Notice that in the example above we pretend 11100 is an unsigned binary number and subtract one. Now, our result from -8 + 4 can be computed 11000b = -8d +00100 = 4d -------------------------- 11100b = -4d

8 Floating Point Representation Representing real numbers in binary is quite simple and is not much different than converting from a decimal integer to binary. Consider 8.5d Notice that a value such as 8 can be represented as an unsigned binary integer as follows: 1000b Notice that values after the decimal point may be represented as a series of ones and zeroes representing the following values: 1/2, 1/4, 1/8, 1/16, 1/32,... Or 2^-1, 2^-2, 2^-3, 2^-4, 2^-5,... Thus, we have the following binary to decimal relationships 0.5d = 0.1b 0.25d = 0.01b 0.0125d = 0.001b...

9 Floating Point Representation Additionally, notice that we can convert from decimal to binary by iteratively multiplying decimal fractions (values after the decimal point) by two until we reach a binary value. Notice that the values before the decimal point represent our binary fraction. Consider 0.5d 0.5d * 2 ----------- <-- binary "decimal" point 1.0d Result is 0.1b = 2^-1 = 1/2 = 0.5d Consider 0.25d 0.25d * 2 ------------- 0.5d * 2 1.0d Result is 0.01b = 0 * 2^-1 + 1 * 2^-2 = 1/4 = 0.25d

10 Floating Point Representation Consider 0.125d 0.0125d * 2 ----------------- 0.25d * 2 0.5d * 2 1.0d Result is 0.001b = 0 * 2^-1 + 0 * 2^-2 + 1 * 2^-3 = 1/8 = 0.125d Consider another value such as 0.75d. A conversion to binary is performed as follows: 0.75d * 2 ------------- 1.5d --> 0.5d*2 notice that we only multiply values after the decimal point by 1.0d Result is 0.11b = 1*2^-1 + 1*2^-2 = 1/2 + 1/4 = 3/4 = 0.75d

11 Floating Point Representation Now, lets look at 0.4d 0.4d * 2 ------------ 0.8d * 2 1.6d --> 0.6d * 2 1.2d --> 0.2d * 2 0.4d * 2 0.8d * 2 1.6d --> 0.6d * 2 1.2d --> 0.2d * 2 0.4d * 2 0.8d * 2 1.6d --> 0.6d * 2 1.2d --> 0.2d * 2 0.4d * 2... Result is 0.0110011001100110011...b = 0*2^-1 + 1*2^-2 + 1*2^-3 + 0*2^-4 + 0*2^-5 + 1*2^-6 + 1*2^-7 + 0*2^-8 + 0*2^-9 + 1*2^-10...

12 Floating Point Representation Notice that this result is an infinitely repeating series. Just like in decimal, where values suchas 1/3 may only be displayed as a decimal expansion of an infinitely repeating series, binary expansions may result in infinitely repeating series. If we sum 10 bits from the results of the binary expansion of 0.4d, we can get anapproximation for the value. Notice, 1/4 + 1/8 + 1/64 + 1/128 + 1/1024 = 0.39941406dThis is a near approximation to 0.4d

13 Example Consider a number such as 123.45d 123 % 2 = 1 61 % 2 = 1 30 % 2 = 0 15 % 2 = 1 7 % 2 = 1 3 % 2 = 1 1 0.45d * 2 ----------- 0.9d * 2 1.8d --> 0.8d * 2 1.6d --> 0.6d * 2 1.2d --> 0.2d * 2 0.4d * 2 0.8d * 2 1.6d --> 0.6d * 2 1.2d --> 0.2d * 2 0.4d * 2 0.8d * 2 1.6d --> 0.6d * 2 1.2d --> 0.2d * 2 0.4d * 2... Now the result is:1111011.0111001100110011...

14 IEEE Standard Again notice that we convert the values after the decimal point to binary by iterativelymultiplying all digits after the decimal point by two. Notice that if we are going to convert this to a representation that the computer can understand, we will have to limit the precision or the number of bits after the decimal place. IEEE Standard 754 denotes the standard representation for floating point numbers. 32 bit floating point numbers are represented in binary scientific notation. Recall that decimal floating point numbers are represented as follows: +/- x.xxxxx * 10 ^ +/- y where x is the significand and y is the exponent.

15 IEEE Standard In binary, we may represent scientific notation as: +/- x.xxxxxx * 2 ^ +/- y sign-bitexponentsignificand 1-bit8-bit23-bit The sign bit denotes whether the significand is positive or negative The exponent is a biased binary number and may represent a value between -126 and 127 The significand represents an unsigned binary value less than 2 decimal. Notice that this value will always be greater than or equal to one unless it is zero. Therefore, we will ignorethe leading one in the significand. Simply put, the significand denotes the significant bits of the value we are trying to represent.


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

Similar presentations


Ads by Google