In: Computer Science
1) Represent -34 and +67 in the following ways: a) 8 bit sign and magnitude representation with MSB as sign bit. b) 8 bit 1’s complement representation. c) 8 bit 2’s complement representation. 2) Convert the decimal numbers 40 and 20 into 8-bit unsigned binary representation and add the two numbers.
1) a) -34 ------ This is negative. so, follow these steps to convert this to various binary formats. Divide 34 successively by 2 until the quotient is 0 34/2 = 17, remainder is 0 17/2 = 8, remainder is 1 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 100010 Adding 2 zeros on left hand side of this number to make this of length 8 So, 34 in normal binary format is 00100010 sign-magnitude: ----------------- set 1 as left most bit, since this number is negative. so, 00100010 becomes 10100010 ===================================== || sign-magnitude: 10100010 || ===================================== 1's complement: ----------------- flip all the bits. Flip all 0's to 1 and all 1's to 0. 00100010 is flipped to 11011101 ===================================== || 1's complement: 11011101 || ===================================== 2's complement: ----------------- Add 1 to above result 11011101 + 1 = 11011110 ===================================== || 2's complement: 11011110 || ===================================== b) 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 Adding 1 zero(s) on left hand side of this number to make this of length 8 So, 67 in normal binary format is 01000011 ===================================== || 1's complement: 01000011 || || 2's complement: 01000011 || || sign-magnitude: 01000011 || =====================================