如何在 circuitikz 中绘制完整的减法器电路?

如何在 circuitikz 中绘制完整的减法器电路?

我想做以下全减法器电路

在此处输入图片描述

感谢 AJ Physics Studio 频道,全加器

在此处输入图片描述

\begin{figure}[ht]
   \centering 
   \begin{circuitikz}[scale=1]
   \draw (0,8) node[xor port](xor1){}
(-4.25, 8.25) node[anchor=east] {A} %%input A
(-4.25, 7.75) node[anchor=east] {B} %%input B
(-4, 6.75) node[anchor=east] {$\text{C}_{in}$} %%input C_in
(2, 7.5) node[xor port] (xor2){} 
(xor2.out) node[anchor=west] {S}
(2, 5.5) node[and port] (and1){}
(2, 3.5) node[and port] (and2){}
(4, 4.5) node[or port] (or){}
(-4, 8.25) to[short, -*](-3, 8.25)-|(xor1.in 1)
(-4, 7.75) to[short, -*](-2.5, 7.75)-|(xor1.in 2)
(-4, 6.75) to[short, -*](0.6, 6.75)-|(and1.in 1)
(0, 6.75)-|(xor2.in 2)
(0, 8) to[short, -*](0.25, 8)-|(xor2.in 1)

(0.25, 8)--(0.25, 5.25)-|(and1.in 2)
(-3, 8.25)--(-3, 3.25)-|(and2.in 2)
(-2.5, 7.75)--(-2.5, 3.75)-|(and2.in 1)
(and1.out)-|(or.in 1)
(and2.out)-|(or.in 2)
(or.out) node[anchor=west]{$\text{C}_{out}$}
;
\end{circuitikz}
\end{figure}

我正在努力做到这一点,但不确定这种方法是否好。我在 Latex 中绘制电路方面还很陌生,我尝试添加非门,如下所示,但仍然令人困惑。

\begin{figure}[ht]
\centering 
\begin{circuitikz}[scale=1]
\draw (0,8) node[xor port](xor1){}
(-4.25, 8.25) node[anchor=east] {A} %%input A
(-4.25, 7.75) node[anchor=east] {B} %%input B
(-4, 6.75) node[anchor=east] {$\text{C}_{in}$} %%input C_in
(2, 7.5) node[xor port] (xor2){} 
(xor2.out) node[anchor=west] {Q}
(2, 5.5) node[and port] (and1){}
(2, 3.5) node[and port] (and2){}
(4, 4.5) node[or port] (or){}
(-4, 8.25) to[short, -*](-3, 8.25)-|(xor1.in 1)
(-4, 7.75) to[short, -*](-2.5, 7.75)-|(xor1.in 2)
(-4, 6.75) to[short, -*](0.6, 6.75)-|(and1.in 1)
(0, 6.75)-|(xor2.in 2)
(0, 8) to[short, -*](0.25, 8)-|(xor2.in 1)

(-1.5, 3.75) node[not port] (not1){}

(0.25, 8)--(0.25, 5.25)-|(and1.in 2)
(-3, 8.25)--(-3, 3.25)-|(and2.in 2)
(-2.5, 7.75)--(-2.5, 3.75)-|(not1.in 1)

(and1.out)-|(or.in 1)
(and2.out)-|(or.in 2)
(or.out) node[anchor=west]{$\text{C}_{out}$}
;
\end{circuitikz}
\end{figure}

在此处输入图片描述

答案1

您可能喜欢减法器的以下复制品:

在此处输入图片描述

编辑:稍微缩短一点的代码

\documentclass[border=3.141592]{standalone}
\usepackage{circuitikz}
\ctikzset{logic ports=ieee}

\begin{document}
    \begin{circuitikz}[line cap=round,
                       font=\sffamily\bfseries]
\draw (0,2) node (A) [xor port, anchor=in 1] {}
      (0,0) node (B) [and port, anchor=in 1] {};
\node [notcirc, left] at (B.bin 1) {};
%
\draw   (A.in 1)    to [short,-*]   ++  (-0.50,0)   coordinate (Bin)
                    |- (B.in 1)
        (A.in 2)    to [short,-*]   ++  (-0.75,0)   coordinate (Cin)
                    |- (B.in 2)
        (Bin)       to [short]      ++  (-0.75,0)    node[left] {B}
        (Cin)       to [short]      ++  (-0.50,0)    node[left] {C\textsubscript{in}}
        %
        (A.out)     to [short,*-]   ++  (+0.75,0)
                    node (D) [xor port, anchor=in 2] {}
        (D.in 1)    to [short,-*]   ++  (-0.50,0)   coordinate (Din)
                    |- (Bin |- D.north) -- ++ (-0.75,0) node[left] {A}
        %
        (D.in 2) ++ (0,-1)  node (E) [and port,  anchor=in 1] {}
        (D.out)     node[right] {D};          
\node [notcirc, left] at (E.bin 1) {};
%
\draw   (A.out)     |-  (E.in 2)(Din)   |-  (E.in 1)
        (E.out |- B.out) node (F) [or port, anchor=in 2] {} 
                    (F.out) node [right] {B\textsubscript{out}}
        (B.out) --  (F.in 2)
        (E.out) --  (F.in 1);
   \end{circuitikz}
\end{document}

答案2

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage[siunitx, RPvoltages]{circuitikz}
\usetikzlibrary{circuits.logic.US} % TiKZ Library for US Logic Circuits.
\usetikzlibrary{positioning, arrows.meta, calc}
\begin{document}

 \begin{circuitikz}
    \ctikzset{logic ports=ieee,}
    \draw [thick]   
    (0,0)                                       node [or port](or){} 
                                                node [right=2pt of or]{\bfseries $\text{B}_{out}$}
    (or)                            ++(-8,0)    node[and port, scale=1.2](andlower){}
    (or.in 2)           -|(andlower.out)
    (or)                            ++(-3,1)    node[and port,scale=1.2](andupper){}
    (or.in 1)           -| (andupper.out)
    (andupper.in 1)                 ++(-1,0)    node[not port](not1){}
    (andupper.in 1)     -- (not1.out)
    (not1)                          ++(0.5,2)   node[xor port](xor1){}
                                                node[right=2pt of xor1]{\bfseries D}
    (not1)              to [short]  ++(-1,0)    coordinate(a)
                        |-(xor1.in 2)
    (xor1.in 1)         to [short,-*]++(-1,0)   coordinate(aux) 
                        --          ++(-6,0)    node [left]{\bfseries A}
    (andupper.in 2)     -| (aux)
    (andlower.in 1)                 ++(-1,0)    node[not port](not2){}
    (andlower.in 1)     -- (not2.out)
    (not2)                          ++(0.5,2)   node[xor port](xor2){}
    (xor2.in 1)         to [short, -*]
                                    ++(-0.5,0)  coordinate(auxx) 
                        --          ++(-1.5,0)  node [left]{\bfseries B}
    (not2)              -|(auxx)
    (xor2.in 2)         to [short, -*]++(-1,0)  coordinate(auxxx) 
                        --          ++(-1,0)    node [left]{\bfseries $\text{B}_{in}$}
    (andlower.in 2)     -|(auxxx)
    (xor2.out)          -|                      coordinate(b)(a)
    (xor2.out)          to [short,-*](b)        
            ;
    
    
\end{circuitikz}
\end{document}

相关内容