How would you get the 2's complement of a 4 bit number without explicitly using 0001 in the formula (using power - 1111 - or ground - 0000)?
I tried using a splitter but reconstructing the separate 1 bit numbers back to a 4 bit number did not work.
How would you get the 2's complement of a 4 bit number without explicitly using 0001 in the formula (using power - 1111 - or ground - 0000)?
I tried using a splitter but reconstructing the separate 1 bit numbers back to a 4 bit number did not work.
You could put the 4 bits into the upper 4 bits of a byte, negate the byte, then look at the upper four bits.
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.