Search code examples
ones-complement

Signed Magnitude and 1's Complement


I have this problem I am doing where I have to convert this 8-bit signed binary number 10110100 into signed magnitude, 1's complement, and 2's complement.

For signed magnitude I got the value to be -76.

For 1's complement I know I have to flip all the bits, so then I would get 01001011, but my issue is that the first bit in this 1's complement number is a 0 which means that it is a positive number. Can someone explain to me how to make this into a negative 1's complement number without the zero in the front?


Solution

  • Converting a bit pattern into anything else doesn't make sense if you don't say how it is to be interpreted in the first place. I assume you mean you need to interpret the pattern as these three.

    So for signed magnitude, you take the first bit as the sign, and interpret the rest as an unsigned binary number. The result isn't -76.

    For 1's complement, if the first bit is 1, you know it's a negative number. You invert all the bits, interpret the result as an unsigned number, and finally add the - sign at the front. (If the first bit is 0, you skip the inversion step and don't add a - sign.)

    For 2's complement, the process is the same, but after inverting the bits, you add 1.