AND — Bitwise AND

Description
Section titled “Description”AND (Bitwise AND) writes to Dest a word whose every bit is 1 only where the same bit is 1 in both Source A and Source B. It is an output instruction with no state and no status bits. Use AND with a mask to keep some bits of a status word and zero the rest, to test a group of bits at once, or to strip a field out of a packed word before comparing it. Do not use AND to combine two rung conditions; that is what series contacts are for. AND works on whole numbers, not on the true and false of a rung.
Operands
Section titled “Operands”| Operand | Type | Format | Valid Range | Required | Description |
|---|---|---|---|---|---|
| Source A | A whole-number tag, member, element or bit, or a literal | Tag, Tag.Member, Tag[n], Tag.bit, a number |
Any resolvable reference | Yes | The first word. |
| Source B | Same as Source A | Same | Any resolvable reference | Yes | The second word, usually the mask. |
| Dest | A writable whole-number tag, member or element | Tag, Tag.Member, Tag[n] |
SINT, INT or DINT; not a literal, not an input pin | Yes | Where the result is written. |
Write masks in hexadecimal (0x00F0) or binary-minded decimal; either is accepted. A REAL operand is truncated to a whole number before the operation. Dest may be one of the sources.
Scan Behavior
Section titled “Scan Behavior”Prescan
Section titled “Prescan”Nothing. Dest keeps its power-up value.
Rung-condition-in is false
Section titled “Rung-condition-in is false”The instruction does nothing. Dest holds its last value.
Rung-condition-in is true
Section titled “Rung-condition-in is true”Both sources are read, ANDed bit by bit, and the result is written to Dest every scan the rung is true.
Postscan
Section titled “Postscan”Nothing.
Example
Section titled “Example”Scenario: A status word packs several flags. Bits 3 and 2 are the two fault bits, and the rest are informational. The fault bits are isolated so a single compare can act on them.
Tags:
Apply_Mask— Isolate the fault bits, BOOLFlags— Packed status word, INTMask— Bits to keep, INTMasked— Fault bits only, INT
Rung 1:
—] [Apply_Mask———[AND Flags Mask Masked]———Scan 1 — Apply_Mask = 0. Flags reads 45 and Mask reads 12. The rung is false: Masked holds 0.

Scan 2 — Apply_Mask = 1. Masked reads 12: both fault bits are set.

Binary Result
Section titled “Binary Result”AND — Flags AND Mask, INT (16 bits)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0Flags 45 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1Mask 12 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0Masked 12 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 ^ ^ kept where the mask is 1Bits 5 and 0 of Flags are set but the mask is 0 there, so they are dropped. Had only bit 3 been set, Masked would read 8.
See Also
Section titled “See Also”- OR — Bitwise OR (set bits)
- XOR — Bitwise XOR (toggle or compare bits)
- NOT — Bitwise NOT (invert every bit)
- CMP — Compare by expression (
(Flags AND 12) == 12without a Dest) - Move/Logical Instructions — Category index
Test a single bit. XIC Flags.3 reads bit 3 directly; no AND is needed for one bit.
Clear bits. AND with the inverse of a mask clears those bits: AND Word 0xFFF3 Word clears bits 3 and 2. NOT builds the inverse from the mask if it is a tag.
Signed values. A negative number has bit 15 set (INT) or bit 31 (DINT). AND Word 0x7FFF Word clears the sign bit and leaves the magnitude bits.
The block never colours. Watch the rung wire and the Dest value line.
Applies to LadderIDE >=1.2.2 · Last reviewed 2026-09-11 · Screenshots verified 2026-09-11