Skip to main content

Circuit giving 2's complement of a 4-bit number

Short answer

Output Y0 = A0, Y1 = A1⊕A0, Y2 = A2⊕(A1+A0), Y3 = A3⊕(A2+A1+A0). Realized with three XOR and two OR gates. This implements the rule: copy bits from LSB up to and including the first 1, then invert all higher bits.

Design a combinational circuit whose input is 4-bit number and output is 2's complement of input number.

The circuit takes a 4-bit number A3A2A1A0A_3A_2A_1A_0 and gives Y3Y2Y1Y0Y_3Y_2Y_1Y_0 = its 2's complement (A‾+1\overline{A} + 1, keeping 4 bits).

Truth table

A3A2A1A0A_3A_2A_1A_0Y3Y2Y1Y0Y_3Y_2Y_1Y_0A3A2A1A0A_3A_2A_1A_0Y3Y2Y1Y0Y_3Y_2Y_1Y_0
0000000010001000
0001111110010111
0010111010100110
0011110110110101
0100110011000100
0101101111010011
0110101011100010
0111100111110001

Simplified expressions

From K-maps (or from the rule "copy bits up to and including the first 1 from the right, then invert the rest"):

  • Y0=1Y_0 = 1 for odd numbers only: Y0=A0Y_0 = A_0
  • Y1=1Y_1 = 1 for 01, 10 in A1A0A_1A_0: Y1=A1⊕A0Y_1 = A_1 \oplus A_0
  • Y2Y_2 equals A2A_2 when A1A0=00A_1A_0 = 00, else A2′A_2': Y2=A2⊕(A1+A0)Y_2 = A_2 \oplus (A_1 + A_0)
  • Y3Y_3 equals A3A_3 when A2A1A0=000A_2A_1A_0 = 000, else A3′A_3': Y3=A3⊕(A2+A1+A0)Y_3 = A_3 \oplus (A_2 + A_1 + A_0)
Y0=A0Y1=A1⊕A0Y2=A2⊕(A1+A0)Y3=A3⊕(A2+A1+A0)\begin{aligned} Y_0 &= A_0 \\ Y_1 &= A_1 \oplus A_0 \\ Y_2 &= A_2 \oplus (A_1 + A_0) \\ Y_3 &= A_3 \oplus (A_2 + A_1 + A_0) \end{aligned}

Circuit

A0 ------------------------------> Y0
A1, A0 ----------[XOR]-----------> Y1
A1, A0 --[OR]--> X1 = A1+A0
A2, X1 ----------[XOR]-----------> Y2
A2, X1 --[OR]--> X2 = A2+A1+A0
A3, X2 ----------[XOR]-----------> Y3

Gates: 3 XOR and 2 OR gates (the second OR adds A2A_2 to the first OR output).

Check: A=0110A = 0110: Y0=0Y_0 = 0, Y1=1⊕0=1Y_1 = 1\oplus0 = 1, Y2=1⊕1=0Y_2 = 1\oplus1 = 0, Y3=0⊕1=1Y_3 = 0\oplus1 = 1, so Y=1010Y = 1010, and 16−6=10=101016 - 6 = 10 = 1010. Correct.

(Alternative: invert each bit with NOT gates and add 1 using a 4-bit parallel adder with C0=1C_0 = 1.)

✓ Answer checked by Claude Opus 5.5 (high effort)

All Digital Logic chapter 5 questions →