In: Computer Science
Show the decimal integer -126 in 8-bit sign magnitude, one's complement, two's complement and excess-127 respectively in the given order, separated by comma.
Answer: ---------- 11111110,10000001,10000010,00000001 Explanation: -------------- -126 ------- This is negative. so, follow these steps to convert this to various binary formats. Divide 126 successively by 2 until the quotient is 0 > 126/2 = 63, remainder is 0 > 63/2 = 31, remainder is 1 > 31/2 = 15, remainder is 1 > 15/2 = 7, remainder is 1 > 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 1111110 So, 126 of decimal is 1111110 in binary Adding 1 zeros on left hand side of this number to make this of length 8 So, 126 in normal binary format is 01111110 sign-magnitude: ----------------- set 1 as left most bit, since this number is negative. so, 01111110 becomes 11111110 ===================================== || sign-magnitude: 11111110 || ===================================== 1's complement: ----------------- flip all the bits. Flip all 0's to 1 and all 1's to 0. 01111110 is flipped to 10000001 ===================================== || 1's complement: 10000001 || ===================================== 2's complement: ----------------- Add 1 to above result 10000001 + 1 = 10000010 ===================================== || 2's complement: 10000010 || ===================================== for excess-127: ---------------- add 127 to given number -126 + 127 = 1 in binary 1 is 00000001 ================================= || excess-127: 00000001 || =================================