Method1


In the context of encoding or decoding signed numbers , there are 2 methods at your disposal.

METHOD #1

If the original 2's complement number we want to decode/convert is 1001, we know immediately that it represents a value that is negative-something.

But what value is that something? Unfortunately, it is not simply -1 as you might apply the technique used for the non-negative number evaluation.

So what is it? Because it is not immediately obvious we must decode it by performing an interpretive conversion.

The goal of the decoding process is to find the signed complement of the number, i.e., given a negative representation, if we can convert the number to its positive complement (the same value with an opposite sign) then we can evaluate the magnitude simply as a non-negative value discussed previously

So basically we use the following general strategy:

Given a number that represents negative-X, first convert it to positive-X which we can then evaluate straight forwardly; then remember the original negative sign.

Steps involved are:

  1. Find the 1's complement of the original number. This is simply flipping (complementing) each 1 to a 0 and each 0 to a 1.
  2. Then add 1 to the flipped result.
  3. In so doing, the final result will be it's signed complement, i.e., if the original number was a -X, then the result of going through Steps 1 and 2 now represents +X.

For example:

  • Given an original number, 1001, its 1's complement would be 0110 where each digit is flipped to its opposite value in sequence.
  • Now add 1 to the flipped result (using the 4 rules of binary addition discussed previously): 0110 + 1 = 0111
  • We now note that the number 0111 has a positive sign bit so just sum up the rest of the bits to find the magnitude which in this case is (1x4) + (1x2) + (1x1) = 7 (unsigned).
  • Now remember to combine with the original sign which means that we can conclude that if the signed complement of 1001 turns out to be 0111 or +7,then the original number 1001 must be representing -7.

Here are the steps again:

1001

Original 2's complement number w/ a negative sign representing some value, -x.

0110

1s complement of the original number, i.e., the flipped result.

+ 0001

Adding 1 (preceding 0s added for clarity).

0111

The resulting positive complement of the original negative number turns out to be +7.

So, we infer that original negative number, 1001 must be -7.

Note:

  • While the example above demonstrates the decoding process from negative to positive, we should note that the process is the same for a reverse conversion, i.e., from positive to negative. Try it for yourself - convert +7 to -7.

  • Moreover, the method above involves several steps including the addition operation which could be prone to error. The next method we will consider is a short-cut method that simplifies the conversion process significantly to reduce the risk of errors of conversion.