Bitwise (output instruction)
NOT: Bitwise NOT
Writes the bitwise complement of a register.
Also called: complement, invert, ones complement.
NOT(number, a)Arguments
| Name | What it is | Accepts | Default |
|---|---|---|---|
| destination | What the instruction acts on | a register | required |
| a | Source | a number or a tag | 0 |
Arguments are positional and this table is generated from the simulator's own instruction registry, so it always matches what the engine accepts.
What it does
NOT flips every bit: each 1 becomes a 0 and each 0 becomes a 1. It is not the XIO contact, which examines one bit and inverts the sense of that one examination. NOT rewrites a whole register.
It is used for building masks, for inverting a word from a device that reports active low, and as the middle step in turning a set of bits you want to keep into a set you want to clear.
The result is startling the first time. Because the register is 32 bits and signed, complementing a small positive number gives a large negative one: NOT of 10 is -11. Nothing is wrong. The bits above the ones you were thinking about were all zeros, they are now all ones, and the top bit is the sign. Mask the result down to the bits you actually care about and it makes sense again.
A rung you can run
Invert a word, then mask it back to the bits you meant
ONS(Read_Inputs)MOV(Sensor_Word,10)
NOT(Sensor_Inverted,Sensor_Word)
AND(Sensors_Clear,Sensor_Inverted,15)
EQU(Sensors_Clear,5)OTE(Expected_Pattern)Press Read_Inputs. Sensor_Word is 10, which is 1010, so the sensors at bits 1 and 3 are blocked. The NOT gives -11, which looks alarming and is correct: every one of the 32 bits flipped. The AND with 15 brings it back to the four bits that exist on this machine, giving 5, which is 0101, the two sensors that are clear.
Run this rung in the simulatorWhat it is called on other controllers
| Platform | Equivalent |
|---|---|
| Rockwell (Studio 5000) | NOT |
| Siemens (TIA Portal) | INV |
| Mitsubishi (GX Works) | CML |
| CODESYS and IEC 61131-3 | NOT |
Common mistakes
- Being surprised by the negative number and assuming the instruction is broken. It complemented all 32 bits, exactly as asked. AND the result with a mask of the bits you meant.
- Using it where XIO would do. To act on one bit being off, examine that bit with XIO. NOT is for whole registers.
Practise it
Interactive exercises that use NOT. Each one checks your ladder against a real scan.
