%%%%%%%%%%%%basic logical circuits%%%%%%%%%%
%%%AND (NAND)
\newcommand{\andnand}[3]{
\put(0,0){\framebox(10,15){}}
   \ifnum#1=2
\multiput(0,5)(0,5){2}{\line(-1,0){5}}  % 2 inputs
   \else \ifnum#1=3
\multiput(0,2.5)(0,5){3}{\line(-1,0){5}} % 3 inputs
   \fi  \fi
    \ifnum#2=0
\put(4,10){\&}                % normal
\ifx#3I
\put(10.75,7.5){\circle{1.5}} %inverted output
\put(11.5,7.5){\line(1,0){3}}
      \else  \ifx#3N
\put(10,7.5){\line(1,0){5}}    %noninverted output
      \fi \fi
     \else  \ifnum#2=1
\put(3,10){\&$\triangleright$} % power
\ifx#3I
\put(10.75,7.5){\circle{1.5}} %inverted output
\put(11.5,7.5){\line(1,0){3}}
      \else  \ifx#3N
\put(10,7.5){\line(1,0){5}}    %noninverted output
      \fi \fi
     \else \ifnum#2=2
\put(4,10){\&}               %normal open collector
\put(5,5){$\diamondsuit$}
\put(5.5,4.5){\line(1,0){2}}
\ifx#3I
     \put(10.75,4.5){\circle{1.5}} %inverted output
     \put(11.5,4.5){\line(1,0){3}}
           \else \ifx#3N
      \put(10,4.5){\line(1,0){5}}    %noninverted output
           \fi \fi
     \else \ifnum#2=3
\put(3,10){\&$\triangleright$}   %power open collector
\put(5,5){$\diamondsuit$}
\put(5.5,4.5){\line(1,0){2}}
\ifx#3I
     \put(10.75,4.5){\circle{1.5}} %inverted output
     \put(11.5,4.5){\line(1,0){3}}
           \else \ifx#3N
      \put(10,4.5){\line(1,0){5}}    %noninverted output
           \fi \fi
     \fi \fi \fi \fi
}
%%%%%%OR (NOR)
\newcommand{\ornor}[3]{
\put(0,0){\framebox(10,15){}}
   \ifnum#1=2
\multiput(0,5)(0,5){2}{\line(-1,0){5}}  % 2 inputs
   \else \ifnum#1=3
\multiput(0,2.5)(0,5){3}{\line(-1,0){5}} % 3 inputs
   \fi  \fi
    \ifnum#2=0
\put(4,10){$1$}                % normal
\ifx#3I
\put(10.75,7.5){\circle{1.5}} %inverted output
\put(11.5,7.5){\line(1,0){3}}
      \else  \ifx#3N
\put(10,7.5){\line(1,0){5}}    %noninverted output
      \fi \fi
     \else  \ifnum#2=1
\put(3,10){$1\triangleright$} % power
\ifx#3I
\put(10.75,7.5){\circle{1.5}} %inverted output
\put(11.5,7.5){\line(1,0){3}}
      \else  \ifx#3N
\put(10,7.5){\line(1,0){5}}    %noninverted output
      \fi \fi
     \else \ifnum#2=2
\put(4,10){$1$}               %normal open collector
\put(5,5){$\diamondsuit$}
\put(5.5,4.5){\line(1,0){2}}
\ifx#3I
     \put(10.75,4.5){\circle{1.5}} %inverted output
     \put(11.5,4.5){\line(1,0){3}}
           \else \ifx#3N
      \put(10,4.5){\line(1,0){5}}    %noninverted output
           \fi \fi
     \else \ifnum#2=3
\put(3,10){$1\triangleright$}   %power open collector
\put(5,5){$\diamondsuit$}
\put(5.5,4.5){\line(1,0){2}}
\ifx#3I
     \put(10.75,4.5){\circle{1.5}} %inverted output
     \put(11.5,4.5){\line(1,0){3}}
           \else \ifx#3N
      \put(10,4.5){\line(1,0){5}}    %noninverted output
           \fi \fi
     \fi \fi \fi \fi

}
%%%inverter
\newcommand{\invert}[2]{
\put(0,0){\framebox(10,15){}}
\put(0,7.5){\line(-1,0){5}}  % 1 input
    \ifnum#1=0
\put(4,10){$1$}                % normal
\ifx#2I
\put(10.75,7.5){\circle{1.5}} %inverted output
\put(11.5,7.5){\line(1,0){3}}
      \else  \ifx#2N
\put(10,7.5){\line(1,0){5}}    %noninverted output
      \fi \fi
     \else  \ifnum#1=1
\put(3,10){$1\triangleright$} % power
\ifx#2I
\put(10.75,7.5){\circle{1.5}} %inverted output
\put(11.5,7.5){\line(1,0){3}}
      \else  \ifx#2N
\put(10,7.5){\line(1,0){5}}    %noninverted output
      \fi \fi
     \else \ifnum#1=2
\put(4,10){$1$}               %normal open collector
\put(5,5){$\diamondsuit$}
\put(5.5,4.5){\line(1,0){2}}
\ifx#2I
     \put(10.75,4.5){\circle{1.5}} %inverted output
     \put(11.5,4.5){\line(1,0){3}}
           \else \ifx#2N
      \put(10,4.5){\line(1,0){5}}    %noninverted output
           \fi \fi
     \else \ifnum#1=3
\put(3,10){$1\triangleright$}   %power open collector
\put(5,5){$\diamondsuit$}
\put(5.5,4.5){\line(1,0){2}}
\ifx#2I
     \put(10.75,4.5){\circle{1.5}} %inverted output
     \put(11.5,4.5){\line(1,0){3}}
           \else \ifx#2N
      \put(10,4.5){\line(1,0){5}}    %noninverted output
           \fi \fi
     \fi \fi \fi \fi
}


\endinput
