简体   繁体   English

添加 8 位有符号幅度二进制数 - 二进制算术

[英]add the 8-bit signed magnitude binary numbers - binary arithmetic

I am trying to add 8-bit signed magnitude numbers: 10111000 + 00010111我正在尝试添加 8 位有符号幅度数: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.我知道最高有效位 (MSB) 是符号位,不应添加。 However, I am not getting (-33) as the answer in binary, and there doesn't seem to be an overflow also.但是,我没有得到 (-33) 作为二进制答案,而且似乎也没有溢出。 I am not sure if I am doing it the right way.我不确定我是否以正确的方式做这件事。 Please help.请帮忙。

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 .取较大量级的符号 ( 56 ) 为您提供最终数字1 0 1 0 0 0 0 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM