Skip to content

Logic Gate ​

AND, OR, XOR, NAND, NOR, XNOR or NOT of integer signals, chosen with the Operator parameter. Last bit mode works on bit 0 only: each input counts as 0 or 1 by its lowest bit and the output is always 0 or 1 (NOT 0 = 1). Bitwise mode applies the operator to every bit of the whole integer (10 AND 6 = 2, NOT 0 = -1) for flags packed into one status word.

Category: Digital Logic / Gates

Overview ​

The Logic Gate block is every basic gate in one part. Pick the function with Operator — AND, OR, XOR, NAND, NOR, XNOR or NOT — and the symbol on the canvas redraws to match. NOT has a single input in; every other operator combines two inputs a and b. Switching between NOT and a two-input operator removes the wires on the inputs that disappear.

Mode decides how much of each integer the gate looks at:

  • Last bit (default) — only bit 0 of each input counts, and the output is always 0 or 1. This is the mode for on/off logic: breaker commands, enables, flip-flop inputs, trip flags.
  • Bitwise — the operator is applied to every bit of the whole integer, so one block can combine, test or clear flags packed into a status word. The block shows a small int badge in this mode.

Truth table in Last bit mode ​

abANDORXORNANDNORXNOR
00000111
01011100
10011100
11110001

NOT gives 1 for an input of 0 and 0 for an input of 1.

Only the lowest bit is read, so an input of 2 (binary 10) counts as 0 and an input of 3 (binary 11) counts as 1. Drive the gate from a 0/1 signal — a Relational Int or Relational Double flag, a Clock, a flip-flop output — or pick bit 0 on purpose to test whether a counter is odd.

Bitwise mode ​

Each output bit depends only on the same bit of the two inputs. With a = 10 (binary 1010) and b = 6 (binary 0110):

OperatorOutputBinary
AND20010
OR141110
XOR121100
NAND-3every bit of 0010 inverted
NOR-15every bit of 1110 inverted
XNOR-13every bit of 1100 inverted

Inverting operators go negative in Bitwise mode

Inverting every bit of a whole integer also flips the sign bit, so NOT 0 is −1 (all bits set) and NOT 1 is −2. When the output has to be a 0/1 logic level, use Last bit mode instead.

Combine Bitwise mode with the Bit Operation block (Mask, Bit Extract, Shift Left, Shift Right) to set, clear and read individual flags.

Feeding it from real-valued signals ​

The ports carry integers. To drive the block from a measured or computed real signal, pass the signal through a Double → Int block first, and use an Int → Double block after it if the result has to enter a real-valued block.

Bit Operation, Flip-Flop · Flip-flop truth tables sample

Ports ​

PortKindSignalNotes
in_aControl inputIntegerShown when Operator is not NOT
in_bControl inputIntegerShown when Operator is not NOT
inControl inputIntegerShown when Operator is NOT
outControl outputInteger

Parameters ​

ParameterTypeDefaultUnitsDescriptionID
OperatorChoice: AND / OR / XOR / NAND / NOR / XNOR / NOTAND—Logic function applied to the inputs. NOT has a single input; the other operators combine inputs a and b.op
ModeChoice: Last bit / BitwiseLast bit—Last bit = use only bit 0 of each input; the output is always 0 or 1. Bitwise = apply the operator to every bit of the whole integer, so inverting operators turn 0 into -1 (all bits set).mode