Description
You can use the "Create twos complement" instruction to change the sign of the value at input IN and query the result at output OUT. If there is a positive value at input IN, for example, the negative equivalent of this value is sent to output OUT.
The enable output ENO has the signal state "0" if one of the following conditions applies:
-
Enable input EN has the signal state "0".
-
The result of the instruction is outside the range permitted for the data type specified at output OUT.
-
A floating-point number has an invalid value.
Parameters
The following table shows the parameters of the "Create twos complement" instruction:
|
Parameters |
Declaration |
Data type |
Memory area |
Description |
||
|---|---|---|---|---|---|---|
|
S7-1200 |
S7-1500 |
S7-1200 |
S7-1500 |
|||
|
EN |
Input |
BOOL |
BOOL |
I, Q, M, D, L or constant |
I, Q, M, D, L, T, C or constant |
Enable input |
|
ENO |
Output |
BOOL |
BOOL |
I, Q, M, D, L |
I, Q, M, D, L |
Enable output |
|
IN |
Input |
SINT, INT, DINT, floating-point numbers |
SINT, INT, DINT, LINT, floating-point numbers |
I, Q, M, D, L, P or constant |
I, Q, M, D, L, P or constant |
Input value |
|
OUT |
Output |
SINT, INT, DINT, floating-point numbers |
SINT, INT, DINT, LINT, floating-point numbers |
I, Q, M, D, L, P |
I, Q, M, D, L, P |
Twos complement of the input value |
You can select the data type of the instruction from the "???" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
If the "TagIn" operand has signal state "1", the instruction is executed. The sign of the value at input "TagIn_Value" is changed and the result is stored at output "TagOut_Value". If the instruction is executed without errors, the enable output ENO has the signal state "1" and the "TagOut" output is set.