In: Computer Science
Write -127 as 8 bit signed binary number both using 2'complement and sign/magnitude notation.
1) -127 This is negative. so, follow these steps to convert this into a 2's complement binary Step 1: Divide 127 successively by 2 until the quotient is 0 > 127/2 = 63, remainder is 1 > 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 1111111 So, 127 of decimal is 1111111 in binary So, 127 in normal binary is 01111111 Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0. 01111111 is flipped to 10000000 Step 3:. Add 1 to above result 10000000 + 1 = 10000001 so, -127 in 2's complement binary is 10000001 Answer: 10000001 2) -127 ------- This is negative. so, follow these steps to convert this to various binary formats. Divide 127 successively by 2 until the quotient is 0 > 127/2 = 63, remainder is 1 > 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 1111111 So, 127 of decimal is 1111111 in binary So, 127 in normal binary format is 01111111 sign-magnitude: ----------------- set 1 as left most bit, since this number is negative. so, 01111111 becomes 11111111 Answer: 11111111