简体   繁体   English

4 位二进制数的 9 的补码

[英]9's complement of a 4-bit binary number

I don't understand how to calculate the 9's complement of a binary number.我不明白如何计算二进制数的 9 的补码。 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.我可以将它应用于十进制,例如 15 = (9-1)(9-5) ) 84 然后我想继续进行二进制 -> 十进制 -> 9 的补码 -> 二进制转换,但我想这不是正确的方法行动。

enter image description here在此处输入图片说明

Not sure if you're still looking for help on this, I see it's been two months.不确定你是否还在寻求这方面的帮助,我知道已经两个月了。 But I couldn't find how to do the 9's compliment of a BCD (Binary-Coded Decimal, which is stored in 4 bits up to 1001) anywhere on the front page of google, without converting the binary to decimal.但是我在google首页的任何地方都找不到如何在不将二进制转换为十进制的情况下对BCD(二进制编码的十进制,以4位最高1001存储)进行9的补充。 This doesn't work if you only work in binary, like in an ALU.如果您只在二进制中工作,这将不起作用,例如在 ALU 中。

After a bit of scratching around with 9's compliment on paper in binary, I found the answer.在用二进制在纸上写下 9 的赞美之后,我找到了答案。

You need to take 9 (1001), and add the 2's compliment of the 4-bit binary number that you want the 9's compliment of:您需要取 9 (1001),并添加您想要 9 的补码的 4 位二进制数的 2 的补码:

To find the 9's compliment of 2 (0010) for example例如,找到 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.

Note that there was a carry bit (1) to the left.请注意,左侧有一个进位位 (1)。 This indicates that the final answer is positive.这表明最终答案是肯定的。 For every 9's compliment up to 9, this carry bit will be 1.对于每个 9 的最多 9 的补码,该进位位将为 1。

The 9's compliments for 10 and above requires an extra step: you need to calculate the two's compliment again on the result of step 3. In the following example, I work out the 9's compliment for 13: 9 对 10 及以上的恭维需要一个额外的步骤:你需要根据第 3 步的结果再次计算两个的恭维。在下面的例子中,我计算了 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.

Note that there was no carry bit to the left (0).请注意,左侧 (0) 没有进位位。 This means that the final answer is a negative value: -4.这意味着最终答案是负值:-4。

Whether or not there is a carry bit to the left, will determine whether you need to do a second 2's compliment calculation at step 3, and also whether the final answer is a positive or a negative value.左边是否有进位位,将决定您是否需要在步骤 3 中进行第二次 2 的补码计算,以及最终答案是正值还是负值。

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

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