如何编写以下逻辑门电路?

如何编写以下逻辑门电路?

如何编写以下逻辑门图?

复杂 复杂度2 复杂度3 复杂度4 复杂度5

我目前的尝试:

\begin{circuitikz}
        %Top OR Gate
        \draw
        (0,-1) 
        node[label = left:$A$] {}
        to [short]
        (1,-1)
        node[american or port, anchor = in 1] (or1){}
        (or1.in 2)
        -- ++(-1,0)
        node[label = left:$B$] {}
        to[short]
        (or1.in 2)
        (or1.in 2)
        -- ++(-1,0)
        (or1.out)
        to[short] (2.5,-3)
        node[american and port, anchor = in 1] (and1){}
        (and1.in 2)
        -- ++(-2.5,0)
        node[label = left:$C$] {}
        (0,-5) 
        node[label = left:$D$] {}
        to [short]
        (2.5,-5)
        node[american not port, anchor = in 1] (not1){}
        (and1.out)
        to[short] (4,-4)
        node[american or port, anchor = in 1] (or2){}
        (and1.in 2)
        (not1.out)
        to[short] (4, 52 |- or2.in 2)
        (or2.out)
        -- ++(1,0)
        node[label = right:$X$] {}
        %labels
        (or1.out)
        node[label = right:$X_1$] {}
        (and1.out)
        node[label = right:$X_2$] {}
        (xor2.out)
        node[label = right:$X_3$] {}
        \end{circuitikz}

在此处输入图片描述

答案1

这是一个可行的解决方案;我大量注释了代码以说明其背后的原因。我并不是说这是唯一的方法;但请注意,我只在需要的地方使用显式坐标(数字),因此只需更改其中一个即可改变电路的间距,使其保持一致。

\documentclass[margin=1cm]{standalone}

\usepackage{circuitikz}
% IEEE standard ports are much nicer
\ctikzset{logic ports=ieee}
\begin{document}
\begin{tikzpicture}
    % let's start with the first port. The ++(1,0) will select how much to the right
    % from the connection is. Change this to have more space, the rest will follow.
    \draw (0,0) coordinate (start) node[left]{$A$} -- ++(1,0) 
        node[or port, anchor=in 1](or1){} (or1.out) node[right]{$X_1$};
    % second input, below the first one
    % (X -| Y) means: go horizontal from X, vertical from Y
    \draw (or1.in 2) -- (or1.in 2 -| start) node[left]{$B$};
    % the second port will be below and to the right the first one.
    \draw (or1.out) -- ++(0,-1) node[and port, anchor=in 1](and1){}
        (and1.out) node[right]{$X_2$};
    \draw (and1.in 2) -- (and1.in 2 -| start) node[left]{$C$};
    % now, if you really want the not at the same level of and1...
    % we move down for input 2 of and1 without stroking
    \draw (and1.in 2) ++(0,-1) node [not port, anchor=in](not1){}
        % we want the X3 label at the same x-position that X2
        (not1.out -| and1.out) node[right]{$X_3$};
    \draw (not1.in) -- (not1.in -| start) node[left]{$D$};
    % trick here: put the next or midway from and1 and not1
    \draw ($(and1.out)!0.5!(not1.out)$) ++(2,0) node[or port](or2){}
        (or2.out) node[right]{$X$};
    % let do a nice connection here: |- means go vertically then horizontally
    \draw (and1.out) |- (or2.in 1);
    % a little bit trickier for the not, because it's shorter: let's go
    % horizontally  until the above kink, and then |-
    \draw (not1.out) -- (not1.out -| and1.out) |- (or2.in 2);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容