Logic Gates

Logic gates can be drawn by importing the logic module:

from SchemDraw import logic

Typical AND, OR, NAND, NOR, XOR, XNOR, and NOT gates with 2, 3, or 4 inputs are predefined. Anchors are defined as ‘in1’, ‘in2’, etc. for each input, and ‘out’ for the output.

../_images/logic_1_0.svg

Two functions are available to generate gates with higher number of inputs, including invert-bubbles on the inputs. The andgate() and orgate() method:

SchemDraw.logic.andgate(inputs=2, nand=False, inputnots=[])
Parameters
  • inputs (int) – number of inputs

  • nand (bool) – add invert bubble on the output, making a NAND gate

  • inputnots (list) – Input numbers (starting with 1) that have invert bubble

Return type

dict

Returns

element definition dictionary

SchemDraw.logic.orgate(inputs=2, nor=False, xor=False, inputnots=[])
Parameters
  • inputs (int) – number of inputs

  • nor (bool) – add invert bubble on the output, making a NOR gate

  • xor (bool) – draw as exclusive-or gate

  • inputnots (list) – Input numbers (starting with 1) that have invert bubble

Return type

dict

Returns

element definition dictionary

As an example, the following line generates a 3-input NAND gate with one input pre-inverted.

gate = logic.andgate(inputs=3, nand=True, inputnots=[1])
../_images/logic_3_0.svg