BIT103 ยท 2077 ยท 10 marks
Design a combinational circuit whose input is a four-bit number and output is 2's complement of the input number.
Design a combinational circuit whose input is a four-bit number and output is 2's complement of the input number.[10]
Quick answer
The 2's complement of a binary number is obtained by: 1. Taking the 1's complement (inverting all bits), then 2. Adding 1 to the result
Design of Combinational Circuit for 2's Complement of a 4-bit Number
Concept
For a 4-bit input A = AโAโAโAโ, the output is S = SโSโSโSโ
Truth Table
The 2's complement of N is: S = 2โด - N = 16 - N
| Aโ | Aโ | Aโ | Aโ | Sโ | Sโ | Sโ | Sโ |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 |
| 0 | 0 | 1 | 0 | 1 | 1 | 1 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 |
| 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
| 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
Logical Design Approach
The copy-and-invert rule
There is a well-known pattern for the 2's complement:
Copy all bits from the right up to and including the first 1, then invert every bit above it.
The rule follows from the definition. Complementing every bit gives $\overline{A_i}$, and adding 1 to that propagates a carry only while the complemented bits are 1, that is only while the original bits are 0. So with $B_i = \overline{A_i}$ and an initial carry $C_0 = 1$:
$$S_i = B_i \oplus C_i = \overline{A_i} \oplus C_i$$
$$C_{i+1} = B_i \cdot C_i = \overline{A_i} \cdot C_i$$
The complement must appear in BOTH equations. Using $A_i$ rather than $\overline{A_i}$ builds an incrementer that computes $A + 1$, not the 2's complement.
Boolean Expressions
Carry Equations:
$$C_0 = 1$$
$$C_1 = \overline{A_0} \cdot C_0 = \overline{A_0}$$
$$C_2 = \overline{A_1} \cdot C_1 = \overline{A_1} \cdot \overline{A_0} = \overline{A_1 + A_0}$$
$$C_3 = \overline{A_2} \cdot C_2 = \overline{A_2 + A_1 + A_0}$$
Output Equations:
Since $\overline{x} \oplus \overline{y} = x \oplus y$, each output simplifies neatly:
$$\boxed{S_0 = \overline{A_0} \oplus 1 = A_0}$$
$$\boxed{S_1 = \overline{A_1} \oplus \overline{A_0} = A_1 \oplus A_0}$$
$$\boxed{S_2 = A_2 \oplus (A_1 + A_0)}$$
$$\boxed{S_3 = A_3 \oplus (A_2 + A_1 + A_0)}$$
Read together these are exactly the copy-and-invert rule: $S_0$ is a plain copy of $A_0$, and each higher bit is inverted precisely when some lower bit is 1, which is when the first 1 has already been passed.
Circuit Diagram
A0 โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ S0 (direct connection)
A1 โโโ
XOR โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ S1
A0 โโโ
A1 โโโ
OR โโ P1 = A1 + A0 โโโ
A0 โโโ XOR โโโโโโโโโโโโโโโโโโโโโ S2
A2 โโโโโโโโโโโโโโโโโโโโโโโโ
A2 โโโ
OR โโ P2 = A2 + P1 โโโ
P1 โโโ XOR โโโโโโโโโโโโโโโโโโโโโ S3
A3 โโโโโโโโโโโโโโโโโโโโโโโโ
Gates required: two OR gates (the second reuses the output of the first) and three XOR gates. $S_0$ needs no gate at all, so seven gate inputs in total realise the whole circuit.
Verification
Take A = 0110 (decimal 6). Then $A_0 = 0$, $A_1 = 1$, $A_2 = 1$, $A_3 = 0$, so
$$S_0 = A_0 = 0$$
$$S_1 = A_1 \oplus A_0 = 1 \oplus 0 = 1$$
$$S_2 = A_2 \oplus (A_1 + A_0) = 1 \oplus 1 = 0$$
$$S_3 = A_3 \oplus (A_2 + A_1 + A_0) = 0 \oplus 1 = 1$$
The output is S = 1010 (decimal 10), and $16 - 6 = 10$, which agrees with the truth table row for 0110.
Checking the two extremes as well: for $A = 0000$ every OR term is 0 and every output is 0, which is correct because the 2's complement of zero is zero; for $A = 1111$ the outputs are $1, 0, 0, 0$ read from $S_0$, giving $S = 0001$, and $16 - 15 = 1$.
Conclusion
The 2's complement circuit does not need a full adder chain. Because the carry out of the increment propagates only while the complemented bits are 1, each output reduces to $S_i = \overline{A_i} \oplus C_i$ with $C_{i+1} = \overline{A_i} \cdot C_i$ and $C_0 = 1$, which flattens to a copy of $A_0$ and an XOR of each higher bit with the OR of all bits below it. Two OR gates and three XOR gates are enough.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.