XOR — Bitwise Exclusive OR

Description
Section titled “Description”XOR (Bitwise Exclusive OR) writes to Dest a word whose every bit is 1 where Source A and Source B differ, and 0 where they agree. It is an output instruction with no state and no status bits. Use XOR to find which bits changed between two readings of a word, to toggle chosen bits with a mask, or to compare two words for any difference. Do not use XOR for a single bit toggle that must happen once per event; without an ONS ahead of it the bit flips every scan.
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, or the toggle 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. |
A REAL operand is truncated to a whole number first. 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, XORed 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 block of digital inputs is read into one word each scan, and the previous scan’s word is kept. XOR of the two shows which inputs changed since last scan, so a single NEQ Changed 0 can trigger a log entry.
Tags:
Compare_Now— Compare the two words, BOOLInputs_Now— Inputs this scan, INTInputs_Prev— Inputs last scan, INTChanged— Bits that differ, INT
Rung 1:
—] [Compare_Now———[XOR Inputs_Now Inputs_Prev Changed]———Scan 1 — Compare_Now = 0. Inputs_Now reads 45 and Inputs_Prev reads 41. The rung is false: Changed holds 0.

Scan 2 — Compare_Now = 1. Changed reads 4: only bit 2 differs.

Binary Result
Section titled “Binary Result”XOR — Inputs_Now XOR Inputs_Prev, INT (16 bits)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0Inputs_Now 45 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1Inputs_Prev 41 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1Changed 4 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 ^ 1 where they differBits 5, 3 and 0 are set in both words and come out 0. Bit 2 is set in one and clear in the other and comes out 1.
See Also
Section titled “See Also”- AND — Bitwise AND
- OR — Bitwise OR
- NOT — Bitwise NOT (XOR with all ones)
- NEQ — Not Equal (act on a non-zero
Changed) - Move/Logical Instructions — Category index
Toggle bits. XOR Word 0x0001 Word flips bit 0 each time it runs. Put an ONS ahead of it or the bit flips on every scan.
Two words equal. XOR gives 0 exactly when the two words are identical, which is what EQU A B tests without a Dest.
Round out the change detector. Follow the XOR with MOV Inputs_Now Inputs_Prev on the same rung so the previous word is refreshed after the comparison.
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