Appearance
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
intbadge in this mode.
Truth table in Last bit mode
| a | b | AND | OR | XOR | NAND | NOR | XNOR |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
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):
| Operator | Output | Binary |
|---|---|---|
| AND | 2 | 0010 |
| OR | 14 | 1110 |
| XOR | 12 | 1100 |
| NAND | -3 | every bit of 0010 inverted |
| NOR | -15 | every bit of 1110 inverted |
| XNOR | -13 | every 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.
Related
Bit Operation, Flip-Flop · Flip-flop truth tables sample
Ports
| Port | Kind | Signal | Notes |
|---|---|---|---|
in_a | Control input | Integer | Shown when Operator is not NOT |
in_b | Control input | Integer | Shown when Operator is not NOT |
in | Control input | Integer | Shown when Operator is NOT |
out | Control output | Integer |
Parameters
| Parameter | Type | Default | Units | Description | ID |
|---|---|---|---|---|---|
| Operator | Choice: AND / OR / XOR / NAND / NOR / XNOR / NOT | AND | — | Logic function applied to the inputs. NOT has a single input; the other operators combine inputs a and b. | op |
| Mode | Choice: Last bit / Bitwise | Last 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 |