Signed binary arithmetic

317 Views Asked by At

I'm having trouble with a fairly simply concept, signed binary arithmetic. I know how to do 1's and 2's complement, convert from binary, decimal, octal, and hex, multiply and add bytes and bits, but for some reason this is stumping me:

Take 77 - 99 + 44 for example.

    77 > 01001101
 -(99) > 01100011
         10011100
         +      1   2's complement
         10011101
    44 > 00101100

At this point, I thought I could just take the sum of 77 and the 2's complement of 99, but I feel like I'm going in the wrong direction after completing that step and then adding 44, like below:

   77 >   01001101
-(99) > + 10011101
        = 00000010
   44 > + 00101100 (cut off ending 1, past 8)
        = 00101111

What am I missing? Thanks

Update: I've followed this example, and it shows that when dealing with a 1 (negative) sign bit in a given result, to do another 2's complement with the result, but I am not getting that result.

1

There are 1 best solutions below

6
On BEST ANSWER
  • $+77 = 0~1~0~0~1~1~0~1$
  • $-99 = 1~0~0~1~1~1~0~1$

Adding these produces $-22$, that is:

  • $-22 = 1~1~1~0~1~0~1~0$

Now, we want to add that to $+44$:

  • $+44 = 0~0~1~0~1~1~0~0$

Adding these produces:

  • $-22 + 44 = 1~0~0~0~1~0~1~1~0$

Discard the overflow (MSB) and we are left with the result $= 22$.