Skip to content

AND — Bitwise AND

Category
Move / Logical
Type
Output
Availability
All platforms

AND instruction block: Source A Flags, Source B Mask, Dest Masked


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.


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.


Nothing. Dest keeps its power-up value.

The instruction does nothing. Dest holds its last value.

Both sources are read, ANDed bit by bit, and the result is written to Dest every scan the rung is true.

Nothing.


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, BOOL
  • Flags — Packed status word, INT
  • Mask — Bits to keep, INT
  • Masked — 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.

Figure 1 — AND rung false: Flags 45, Mask 12, Masked 0, rung dark

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

Figure 2 — AND rung true: Masked reads 12, rung lit


AND — Flags AND Mask, INT (16 bits)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Flags 45 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1
Mask 12 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0
Masked 12 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0
^ ^
kept where the mask is 1

Bits 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.


  • 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) == 12 without 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