0

I don't understand how to calculate the 9's complement of a binary number. I can apply it to decimal ones, example 15 = (9-1)(9-5) ) 84 then I thought to proceed with a binary -> decimal -> 9's complement -> binary conversion but I guess it's not the right way to act.

enter image description here

4

1 回答 1

1

不知道你是否还在寻求帮助,我知道已经两个月了。但是我在谷歌首页的任何地方都找不到如何在不将二进制转换为十进制的情况下对 BCD(二进制编码的十进制,以 4 位最多 1001 位存储)进行 9 的补码。如果您只使用二进制文件(例如 ALU),这将不起作用。

在对二进制纸上的 9 的恭维进行了一番摸索之后,我找到了答案。

您需要取 9 (1001),并添加您想要 9 的补码的 4 位二进制数的 2 补码:

例如,要找到 2 (0010) 的 9 的补码

1. 1's compliment of 0010 = 1101
2. Add 0001 to get the 2's compliment = 1110
3. Add this to 1001 (9) = (1) 0111

This  can be tested in decimal: 0111 = 7, and 9 - 2 = 7.

请注意,左侧有一个进位位 (1)。这表明最终的答案是肯定的。对于最多 9 个 9 的补码,该进位位将为 1。

9 对 10 及以上的恭维需要一个额外的步骤:您需要根据第 3 步的结果再次计算 2 的恭维。在以下示例中,我计算出 9 对 13 的恭维:

1. 1's compliment of 1101 = 0010
2. Add 0001 to get the 2's compliment = 0011
3. Add this to 1001 (9) = (0) 1100 (note that the carry bit = 0)
4. 1's compliment of 1100 = 0011
5. Add 0001 to get 2's compliment = 0100

In decimal: 9 - 13 = -4.

请注意,左侧没有进位 (0)。这意味着最终答案是负值:-4。

左边是否有进位,将决定您是否需要在第 3 步进行第二次 2 的补码计算,以及最终答案是正值还是负值。

于 2017-06-01T18:07:46.600 回答