Arithmetic instructions
447
Part III FP Instructions
F85_NEG
16-bit data two's complement
Two’s complement is a number system used to express positive and negative numbers in binary
format. In this system, the number becomes negative if the most significant bit (MSB) of data is 1.
Two’s complement is obtained by inverting all bits and adding 1 to the inverted result.
This instruction is useful for inverting the sign of 16-bit data from positive to negative or from
negative to positive.
·········
d
15
11
12
1
11
1
87
1
43
01
0
1
·········
d
15
00
12
0
11
0
87
0
43
0
0
1
100000000
3
11111111
-3
Destination
Destination
Bit position
Bit position
Decimal data
start: ON
Decimal data
This instruction also exists as a P instruction (for FP2/2SH, FP3/5, FP10/10SH PLC types), which
is only executed at the rising edge of the EN trigger. Select [Insert P instruction] from the
"Instructions" pane if you require a P instruction. To facilitate reuse, the instruction then appears
under "Recently used" in the pop-up menu. Press <Ctrl>+<Shift>+<v> within the programming
area to open the list of recently used elements.
PLC types
Availability of F85_NEG (see page 1326)
Variable Data type Function
d ANY16 16-bit area for storing original data and its two's complement
For Relay T/C Register Constant
d - WY WR WL SV EV DT LD FL -
Description
Takes two's complement of 16-bit data specified by d if the trigger EN is in the ON-state. Two's
complement of the original 16-bit data is stored in d.
Data types
Operands
Example
In this example, the same POU header is used for all programming languages. For an example
using IL (instruction list), please refer to the online help.
POU header
All input and output variables used for programming this function have been declared in the POU
header.
Body
When the variable start changes from FALSE to TRUE, the function is carried out.