In: Computer Science
1. Please convert the following decimal numbers to 8-bit binary sign magnitude and to 8-bit 2’s complement. Please show your work if there are multiple steps. Sign Magnitude 2’s complement a. +67 b. +40 c. -28 d. -40
a) 67 ----- Since this is a positive number. we can directly convert this into binary Divide 67 successively by 2 until the quotient is 0 > 67/2 = 33, remainder is 1 > 33/2 = 16, remainder is 1 > 16/2 = 8, remainder is 0 > 8/2 = 4, remainder is 0 > 4/2 = 2, remainder is 0 > 2/2 = 1, remainder is 0 > 1/2 = 0, remainder is 1 Read remainders from the bottom to top as 1000011 So, 67 of decimal is 1000011 in binary So, 67 in normal binary format is 01000011 ===================================== || 1's complement: 01000011 || || 2's complement: 01000011 || || sign-magnitude: 01000011 || ===================================== b) 40 ----- Since this is a positive number. we can directly convert this into binary Divide 40 successively by 2 until the quotient is 0 > 40/2 = 20, remainder is 0 > 20/2 = 10, remainder is 0 > 10/2 = 5, remainder is 0 > 5/2 = 2, remainder is 1 > 2/2 = 1, remainder is 0 > 1/2 = 0, remainder is 1 Read remainders from the bottom to top as 101000 So, 40 of decimal is 101000 in binary So, 40 in normal binary format is 00101000 ===================================== || 1's complement: 00101000 || || 2's complement: 00101000 || || sign-magnitude: 00101000 || ===================================== c) -28 ------ This is negative. so, follow these steps to convert this to various binary formats. Divide 28 successively by 2 until the quotient is 0 > 28/2 = 14, remainder is 0 > 14/2 = 7, remainder is 0 > 7/2 = 3, remainder is 1 > 3/2 = 1, remainder is 1 > 1/2 = 0, remainder is 1 Read remainders from the bottom to top as 11100 So, 28 of decimal is 11100 in binary So, 28 in normal binary format is 00011100 sign-magnitude: ----------------- set 1 as left most bit, since this number is negative. so, 00011100 becomes 10011100 ===================================== || sign-magnitude: 10011100 || ===================================== 1's complement: ----------------- flip all the bits. Flip all 0's to 1 and all 1's to 0. 00011100 is flipped to 11100011 ===================================== || 1's complement: 11100011 || ===================================== 2's complement: ----------------- Add 1 to above result 11100011 + 1 = 11100100 ===================================== || 2's complement: 11100100 || ===================================== d) -40 ------ This is negative. so, follow these steps to convert this to various binary formats. Divide 40 successively by 2 until the quotient is 0 > 40/2 = 20, remainder is 0 > 20/2 = 10, remainder is 0 > 10/2 = 5, remainder is 0 > 5/2 = 2, remainder is 1 > 2/2 = 1, remainder is 0 > 1/2 = 0, remainder is 1 Read remainders from the bottom to top as 101000 So, 40 of decimal is 101000 in binary So, 40 in normal binary format is 00101000 sign-magnitude: ----------------- set 1 as left most bit, since this number is negative. so, 00101000 becomes 10101000 ===================================== || sign-magnitude: 10101000 || ===================================== 1's complement: ----------------- flip all the bits. Flip all 0's to 1 and all 1's to 0. 00101000 is flipped to 11010111 ===================================== || 1's complement: 11010111 || ===================================== 2's complement: ----------------- Add 1 to above result 11010111 + 1 = 11011000 ===================================== || 2's complement: 11011000 || =====================================