Search code examples
mathbinarycpu-architecturedata-representation

add the 8-bit signed magnitude binary numbers - binary arithmetic


I am trying to add 8-bit signed magnitude numbers: 10111000 + 00010111

  0   1 1 0 0 0 0 0        carry

  1   0 1 1 1 0 0 0        (-56)
+ 0   0 0 1 0 1 1 1      + (+23)
____________________     ________
      1 0 0 1 1 1 1   !=   (-33)

I know that the most significant bit (MSB) is the sign bit and should not be added. However, I am not getting (-33) as the answer in binary, and there doesn't seem to be an overflow also. I am not sure if I am doing it the right way. Please help.


Solution

  • Addition in sign-magnitude representations is unfortunately not as straight-forward as with common complement representations. For sign-magnitude, you need to pick the correct operation based on the combination of signs. If you have equal signs, you simply add the magnitudes. If signs are unequal, you subtract the smaller from the larger and keep the sign of the larger magnitude. So, in your case:

      0 0 0 1 1 1 0        borrow
    
      0 1 1 1 0 0 0        (56)
    - 0 0 1 0 1 1 1      - (23)
    ____________________ ________
      0 1 0 0 0 0 1   ==   (33)
    

    Taking the sign of the larger magnitude (56) gives you the final number 1 0 1 0 0 0 0 1.