使用符号大小和二进制补码的二进制算术

Binary Arithmetic using sign magnitude and two's complement

我正在复习几周后的考试。我有一个我已经回答过的示例问题,但我不确定它是否正确。有人可以帮我验证一下我的答案,如果不正确,请解释哪里出了问题。

问题如下: 考虑符号-量值表示法中的两个二进制变量:A = 011111 和 B = 000001。显示所有涉及的步骤,以二进制格式执行以下操作(即,不要从二进制转换为另一种基数以获得结果)。假设您只有六位可用于答案。

A-B 使用二进制补码。

这是我的回答: 在 B 上使用二进制补码 B = 000001 翻转并加 1

 111110
+000001
 --------
 111111 

然后A + 补码B

 011111
+111111
-------
 011110

最终答案:011110

使用 2 的补码减法 :-

Binary subtraction can be performed by adding the 2's complement of the subtrahend to the minuend. (Minuend in a-b is a and the subtrahend is b in this case)

  1. If a final carry is generated, discard the carry and the answer is given by the remaining bits which is positive(the minuend is greater than the subtrahend).

  2. If the final carry is 0, the answer is negative(the minuend is smaller than the subtrahend) and is in 2's complement form.

现在,B 的 2 的补码 = 111110 + 1 = 111111。

接下来,A + B的2的补码= 011111 + 111111 = 1011110。

如您所见,总和为 7 位,最后进位为 1,因此根据规则 1,我们需要丢弃进位。

所以,最终答案 = 011110。

您的答案与此答案相符,因此,您的答案是正确的。