|
| 1 | +\begin{circuitikz} |
| 2 | +\draw |
| 3 | +% Inputs and outputs: |
| 4 | + (0,4.25) node[ocirc](ain) {} % A node |
| 5 | + (0,4.30) node[left] {{\color{red}$A = 0$}} % A label |
| 6 | + |
| 7 | + (0,3.72) node[ocirc](bin) {} % B node |
| 8 | + (0,3.72) node[left] {{\color{red}$B = 0$}} % B label |
| 9 | + |
| 10 | + (0,1.72) node[ocirc](cin) {} % C-in node |
| 11 | + (0,1.72) node[left] {{\color{red}$Carry_{in} = 1$}} % C-in label |
| 12 | + |
| 13 | + (8.2,1.0) node[ocirc](cout) {} % C-out node |
| 14 | + (8.2,1.0) node[right] {{\color{red}$Carry_{out} = 0$}} % C-out label |
| 15 | + |
| 16 | + (8.2,3.72) node[ocirc, fill=red](sout) {} % S node |
| 17 | + (8.2,3.72) node[right] {{\color{red}$Sum = 1$}} % S label |
| 18 | +; |
| 19 | + |
| 20 | +% Gates: |
| 21 | +\draw |
| 22 | + (2.8,4.0) node[xor port](xorGate1) {} % xor gate 1 |
| 23 | + (3.0,4.9) node[left] {$XOR_1$} % XOR_1 label |
| 24 | + |
| 25 | + (5.5,3.72) node[xor port, fill=yellow](xorGate2) {} % xor gate 2 |
| 26 | + (5.7,4.60) node[left] {$XOR_2$} % XOR_2 label |
| 27 | + |
| 28 | + (2.8, 0.0) node[and port](andGate1) {} % AND gate 1 |
| 29 | + (3.0,-1.0) node[left] {$AND_1$} % AND_1 label |
| 30 | + |
| 31 | + (5.5,2) node[and port](andGate2) {} % AND gate 2 |
| 32 | + (5.7,1) node[left] {$AND_2$} % AND_2 label |
| 33 | + |
| 34 | + (7.75,1.00) node[or port](orGate1) {} % or gate |
| 35 | + (7.55,0.1) node[left] {$OR$} % OR label |
| 36 | +; |
| 37 | + |
| 38 | +% Tie A and B to XOR_1: |
| 39 | +\draw |
| 40 | + (ain) to[short](xorGate1.in 1) |
| 41 | +; |
| 42 | + |
| 43 | +\draw |
| 44 | + (bin) to[short](xorGate1.in 2) |
| 45 | +; |
| 46 | + |
| 47 | +% Tie XOR_1 output to XOR_2 input and to AND_2 input: |
| 48 | +\draw |
| 49 | + (xorGate1.out) |- (xorGate2.in 1) |
| 50 | + (3.5,4.0) node[circ]{} |
| 51 | + (3.5,4.0) |- (andGate2.in 1) |
| 52 | +; |
| 53 | + |
| 54 | +% Tie A and B to AND_1: |
| 55 | +\draw |
| 56 | + (0.5,4.25) node[circ] {} |
| 57 | + (0.5,4.25) |- (andGate1.in 2) |
| 58 | +; |
| 59 | + |
| 60 | +\draw (1.0,3.72) node[circ] {} |
| 61 | + (1.0,3.72) |- (andGate1.in 1) |
| 62 | +; |
| 63 | + |
| 64 | +% Tie C-in to AND_2 and XOR_2: |
| 65 | +\draw[red, very thick] |
| 66 | + (cin) -- (andGate2.in 2) |
| 67 | + (3.0,1.72) node[circ, color=red]{} |
| 68 | + (3.0,1.72) |- (3.0, 3.4) |
| 69 | + (3.0,3.40) |- (xorGate2.in 2) |
| 70 | +; |
| 71 | + |
| 72 | +% Tie AND gate outputs to the OR gate: |
| 73 | +\draw (andGate2.out) |- (6,2) |
| 74 | + (6,2) |- (orGate1.in 1) |
| 75 | +; |
| 76 | + |
| 77 | +\draw (andGate1.out) to[short](6,0) |
| 78 | + (6,0) |- (orGate1.in 2) |
| 79 | +; |
| 80 | + |
| 81 | +% Outputs: |
| 82 | +\draw[very thick, red] (xorGate2.out) -- (sout) % XOR_2 to Sum |
| 83 | +; |
| 84 | + |
| 85 | +\draw (orGate1.out) |- (cout) % OR to Carry-out |
| 86 | +; |
| 87 | + |
| 88 | +\end{circuitikz} |
0 commit comments