1

如果没有在公式中明确使用 0001(使用幂 - 1111 - 或接地 - 0000),您将如何获得 4 位数字的 2 补码?

我尝试使用拆分器,但将单独的 1 位数字重建回 4 位数字不起作用。

4

2 回答 2

1

To calculate two's complement with logic, one typically uses a chain of half adders:

(sum,c_out) = HA(a,b) ==  
 c_out := a & b,
 sum := a ^ b;  

The first HA is actually a tautology: bit_0 == a_0, c_1 == 1, and can be optimized out, if so wanted. Also the last carry out c_4 is rejected.

(bit_0,c_1)   := HA(not a_0, c_0 = 1)
(bit_1,c_2)   := HA(not a_1, c_1)
(bit_2,c_3)   := HA(not a_2, c_2)
(bit_3,[c_4]) := HA(not a_3, c_3)

With assembler one can use the fact that twos_comp(i) for n bit number == 2^n - i, for i!=0.

于 2013-01-28T06:31:55.810 回答
1

您可以将 4 位放入字节的高 4 位,取反字节,然后查看高 4 位。

于 2013-01-28T01:00:54.363 回答