CSC 362 Homework Assignment #1



CSC 362 Homework Assignment #1 answer key

1) Convert 10110011 to decimal assuming the number is stored in each of the following representations:

a. Unsigned magnitude: 128 + 32 + 16 + 2 + 1 = 179

b. Signed magnitude: -(32 + 16 + 2 + 1) = -51

c. One’s complement: negative, flip all bits ( 01001100 = 64 + 8 + 4 = 76, so -76

d. Two’s complement: negative, flip all bits and add 1 ( 01001101 = 64 + 8 + 4 + 1 = 77, so -77

2) Convert 1101100110101000 to decimal assuming that the number is stored in

a. Signed magnitude: -(16384 + 4096 + 2048 + 256 + 128 + 32 + 8) = -22952

b. Two’s complement: negative, flip all bits and add 1 ( 0010011001011000 = 8192 + 1024 + 512 + 64 + 16 + 8 = 9816, so -9816

3) Do the following conversions

a. -25 to 8-bit 2’s complement: 25 = 16 + 8 + 1 = 00011001, for -25, flip all bits and add 1, so -25 = 11100111

b. -1678 to 16-bit 1’s complement: 1678 = 1024 + 512 + 128 + 8 + 4 + 2 = 0000011010001110, for -1678, flip all bits, so -1678 = 1111100101110001

c. -17235 to 16-bit signed magnitude: 17235 = 16384 + 512 + 256 + 64 + 16 + 2 + 1 = 0100001101010011, for -17235, add leading sign bit of 1, so -17235 = 1100001101010011

d. 1111000011111101 from 1’s complement to decimal: negative, flip all bits for positive: 0000111100000010 = 2048 + 1024 + 512 + 256 + 2 = 3842, so -3842

e. 1101101100111000 from 2’s complement to decimal: negative, flip all bits and add 1: 0010010011001000 = 8192 + 1024 + 128 + 64 + 8 = 9416, so -9416

4)

a. 01011110000111 to decimal: sign bit = 0 (positive), exponent = 10111, mantissa = 10000111, or +.10000111*210111, the exponent is in excess 16, so it is really 7 which gives us +.10000111*27 = 1000011.1 = 64 + 2 + 1 + .5 = 67.5.

b. -3.15625 to binary: sign bit = 1, convert 3.15625 to binary = 2 + 1 + 1/8 + 1/32 = 11.00101. Normalize by shifting the decimal point before the first 1 gives us .11001010 * 22. Converting the exponent into excess 16 gives us 10010, so our exponent is 10010 and our mantissa is 11001010. The number is then 11001011001010, or 1 10010 11001010 for readability.

c. 10111011011000 to decimal: sign bit = 1 (negative), exponent = 011011, mantissa = .11011000 = -(.11011 * 201110). The exponent, 01110 is in excess 16, which is really -2. So our value is –(.11011*2-2) = -.0011011 = -(1/8 + 1/16 + 1/64 + 1/128) = -.2109375.

d. 9.8 to binary = 8 + 1 + 1/2 + 1/4 + 1/32 + 1/64 + 1/256 + 1/2048 + … Unfortunately, we will have run out of precision as we only get 8 bits for the mantissa. So 9.8 = 8 + 1 + 1/2 + 1/4 = 1001.1100. We cannot store the rest of the fractional portion. 1001.1100 = .10011100 * 24 = .10011100 * 210100, so our floating point value = 01010010011100 or 0 10100 10011100 for readability. We have lost .05 in precision!

5)

a. 11010 * 10111 (unsigned)

|C |A |Q |M = 10111 |

|0 |00000 |11010 |Q0 = 0, right shift |

|0 |00000 |01101 |Q0 = 1, C||A = A + M |

|0 |10111 |01101 |Right shift |

|0 |01011 |10110 |Q0 = 0, right shift |

|0 |00101 |11011 |Q0 = 1, C||A = A + M |

|0 |11101 |11011 |Right shift |

|0 |01110 |01101 |Q0 = 1, C||A = A + M |

|1 |00101 |01101 |Right shift |

|0 |10010 |10110 |Done |

11010 * 10111 = 1001010110 (26 * 23 = 598)

b. 10110 * 00101 c. 10101 * 10011

|A |Q |Q-1 |M=00101, -M=11011 |

|00000 |10110 |0 |Q0Q-1=00, arithmetic right shift |

|00000 |01011 |0 |Q0Q-1=10, A = A – M |

|11011 |01011 |0 |Arithmetic right shift |

|11101 |10101 |1 |Q0Q-1=11, arithmetic right shift |

|11110 |11010 |1 |Q0Q-1=01, A = A + M |

|00011 |11010 |1 |Arithmetic right shift |

|00001 |11101 |0 |Q0Q-1=10, A = A – M |

|11100 |11101 |0 |Arithmetic right shift |

|11110 |01110 |1 |Done |

|A |Q |Q-1 |M=10011, -M=01101 |

|00000 |10101 |0 |Q0Q-1=10, A = A – M |

|01101 |10101 |0 |Arithmetic right shift |

|00110 |11010 |1 |Q0Q-1=01, A = A + M |

|11001 |11010 |1 |Arithmetic right shift |

|11100 |11101 |0 |Q0Q-1=10, A = A - M |

|01001 |11101 |0 |Arithmetic right shift |

|00100 |11110 |1 |Q0Q-1=01, A = A + M |

|10111 |11110 |1 |Arithmetic right shift |

|11011 |11111 |0 |Q0Q-1=10, A = A – M |

|01000 |11111 |0 |Arithmetic right shift |

|00100 |01111 |1 |Done |

10110 * 00101 = 1111001110 (-10 * 5 = -50)

10101 * 10011 = 0010001111 (-11 * -13 = 143)

d. 110011 / 000101 (unsigned)

|A |Q |M = 000101 |

|000000 |110011 |Left shift |

|000001 |10011_ |A < M, Q0 = 0 |

|000001 |100110 |Left shift |

|000011 |00110_ |A < M, Q0 = 0 |

|000011 |001100 |Left shift |

|000110 |01100_ |A >= M, Q0 = 1, A = A – M |

|000001 |011001 |Left shift |

|000010 |11001_ |A < M, Q0 = 0 |

|000010 |110010 |Left shift |

|000101 |10010_ |A >= M, Q0 = 1, A = A – M |

|000000 |100101 |Left shift |

|000001 |00101_ |A < M, Q0 = 0 |

|000001 |001010 |Done |

110011 / 000101 = 001010 with a remainder of 000001 (51 / 5 = 10 with a remainder of 1)

e. 111101 / 000011 (unsigned)

|A |Q |M = 000011 |

|000000 |111101 |Left shift |

|000001 |11101_ |A < M, Q0 = 0 |

|000001 |111010 |Left shift |

|000011 |11010_ |A >= M, Q0 = 1, A = A – M |

|000000 |110101 |Left shift |

|000001 |10101_ |A < M, Q0 = 0 |

|000001 |101010 |Left shift |

|000011 |01010_ |A >= M, Q0 = 1, A = A – M |

|000000 |010101 |Left shift |

|000000 |10101_ |A < M, Q0 = 0 |

|000000 |101010 |Left shift |

|000001 |01010_ |A < M, Q0 = 0 |

|000001 |010100 |Done |

111101 / 000011 = 010100 with a remainder of 000001 (61 / 3 = 20 with a remainder of 1)

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download