cs345 Homework 8 Solution 1. a) 204.5 204 % 2 = 0 102 % 2 = 0 51 % 2 = 1 25 % 2 = 1 12 % 2 = 0 6 % 2 = 0 3 % 2 = 1 1 0.5 * 2 --------- Binary point -------- 1.0 * 2 204.5 is 11001100.1000000000000000000000000000 . . . Moving the binary point to the right seven places yields: 1.1001100100000000000000000000000 . . . * 2^7 Using 8-bit biased binary, if we assume 0 to be at 127 (0111 1111), the exponent 7 may be represented as 127 (0111 1111) + 7 (111) = 134 (1000 0110). 0 1000 0110 1001 1001 0000 0000 0000 000 Sign bit Exponent Significand b) 12.785 12 % 2 = 0 6 % 2 = 0 3 % 2 = 1 1 0.785 * 2 ---------Binary point--------- 1.57 --> 0.57 * 2 1.14 --> 0.14 * 2 0.28 * 2 0.56 * 2 1.12 --> 0.12*2 0.24 * 2 0.48 * 2 0.96 * 2 1.92 --> 0.92*2 1.84 --> 0.84*2 1.68 --> 0.68*2 1.36 --> 0.36*2 0.72 * 2 1.44 --> 0.44*2 0.88 * 2 1.76 --> 0.76*2 1.52 --> 0.52 *2 1.04 --> 0.04 * 2 0.08 * 2 0.16 * 2 0.32 * 2 0.64 * 2 1.28 --> 0.28 * 2 0.56 * 2 1.12 --> 0.12*2 0.24 * 2 0.48 * 2 0.96 * 2 1.92 --> 0.92*2 1.84 --> 0.84*2 1.68 --> 0.68*2 1.36 --> 0.36*2 12.785 = 1100.1100 1000 1111 0101 1100 0010 1000 1111 ... = 1.1001 1001 0001 1110 1011 1000 0101 0001 111 ... * 2 ^ 4 0111 1111 (127 d) + 11 (3 d) = 1000 0010 0 1000 0010 1001 1001 0001 1110 1011 100 Sign bit Exponent Significand c) 307.2 307 % 2 = 1 153 % 2 = 1 76 % 2 = 0 38 % 2 = 0 19 % 2 = 1 9 % 2 = 1 4 % 2 = 0 2 % 2 = 0 1 0.2 * 2 --------- 0.4 * 2 0.8 * 2 1.6 --> 0.6 * 2 1.2 --> 0.2 * 2 0.4 --> 0.4 * 2 0.8 * 2 1.6 --> 0.6 * 2 1.2 --> 0.2 * 2 0.4 --> 0.4 * 2 0.8 * 2 1.6 --> 0.6 * 2 1.2 --> 0.2 * 2 0.4 --> 0.4 * 2 0.8 * 2 1.6 --> 0.6 * 2 1.2 --> 0.2 * 2 0.4 --> 0.4 * 2 0.8 * 2 1.6 --> 0.6 * 2 1.2 --> 0.2 * 2 0.4 --> 0.4 * 2 . . . 307.2 = 100110011.0011001100110011001100110011 . . . = 1.0011 0011 0011 0011 0011 0011 0011 0011 0011 . . . * 2 ^ 8 127 + 8 = 135 = 0111 1111 + 1000 = 1000 0111 0 1000 0111 0011 0011 0011 0011 0011 001 Sign bit Exponent Significand d) -0.05432 -0.05432 = 0.0000 1101 1110 0111 1110 1010 0101 1111 1000 0. . . = 1.1011 1100 1111 1101 0100 101 . . . * 2 ^ -5 127 - 5 = 122 = 0111 1010 1 0111 1010 1011 1100 1111 1101 0100 101 Sign bit Exponent Significand 0.05432 * 2 ------Binary point------ 0.10864 * 2 0.21728 * 2 0.43456 * 2 0.86912 * 2 1.73824 --> 0.73824 * 2 1.47648 --> 0.47648 * 2 0.95296 * 2 1.90592 --> 0.90592 * 2 1.81184 --> 0.81184 * 2 1.62368 --> 0.62368 * 2 1.24736 --> 0.24736 * 2 0.49472 * 2 0.98944 * 2 1.97888 --> .97888 * 2 1.95776 --> 0.95776 * 2 1.91552 --> 0.91552 * 2 1.83104 --> 0.83104 * 2 1.66208 --> 0.66208 * 2 1.32416 --> 0.32416 * 2 0.64832 * 2 1.29664 --> 0.29664 * 2 0.59328 * 2 1.18656 --> 0.18656 * 2 0.37312 * 2 0.74624 * 2 1.49248 --> 0.49248 * 2 0.98496 * 2 1.96992 --> 0.96992 * 2 1.93984 --> 0.93984 * 2 1.87968 --> 0.87968 * 2 1.75936 --> 0.75936 * 2 1.51872 --> 0.51872 * 2 1.03744 --> 0.03744 * 2 0.07488 * 2 0.14976 * 2 0.29952 * 2 0.59904 * 2 2. a) A * ~B + ~A * B <-- this is an exclusive or, which cannot be further reduced A B Result -------------- 0 0 0 1 0 1 0 1 1 1 1 0 b) (A + ~A) + (B * ~B) = 1 + 0 = 1 c) B*(A*B*C + B) = B*B*(A*C + 1) = B*1 = B d) A * B * (C + ~D) + A * ~B + C * D = A*B*C + A*B*~D + A*~B + C*D <-- No further reduction 3. //Java and/or test public class HW8 { public static void main(String [] args) { System.out.println(String.format("%x", 0xABCD0000 & 0x12340000)); System.out.println(String.format("%x", 0xABCD0000 | 0x12340000)); } } Output: 2040000 bbfd0000 #MIPS and/or test .data x: .word 0xABCD0000 y: .word 0x12340000 .text main: lw $t1, x lw $t2, y and $t3, $t1, $t2 or $t4, $t1, $t2 Results: $t3: 0x02040000 $t4: 0xbbfd0000 4. See http://monismith.info/cs345/homework/HW8P4a.jpg and http://monismith.info/cs345/homework/HW8P4d.png