Two's Complement Of 16-/32-Bit Bin Data (Sign Inversion) - Mitsubishi MELSEC-Q Series Programming Manual

Hide thumbs Also See for MELSEC-Q Series:
Table of Contents

Advertisement

NEG, DNEG
DNEG(P)
(1) Inverts the sign of the 32-bit device specified for
specified for
Before
execution
Sign
conversion -
After
execution
(2) This instruction is used when inverting positive and negative signs.
Operation Error
No operation error occurs in the execution of the NEG(P) and DNEG(P) instructions.
Program Example
In the following program, the value in Var_D20 is subtracted from the value in Var_D10 when
X0A turns ON, and if the result is negative, the absolute value is defined.
[Structured ladder]
[ST]
IF X0A THEN
END_IF;
6.3 Data Conversion Instructions
6-92

6.3.11 Two's complement of 16-/32-bit BIN data (sign inversion)

.
d
b31
d
1
1
1
1
1
1
0
0
0
0
0
1
1
1
1
1
b31
0
0
0
0
0
d
OUT(Var_D10<Var_D20,M3);
Var_D10:=Var_D10-Var_D20;
NEGP(M3,Var_D10);
and stores the result to the device
d
32 bit
1
1
0
1
0
0
0
0
0
0
0
0
1
1
0
1
0
0
0
0
1
0
1
1
b0
1
0
0
-218460
0
0
0
1
0
0
b0
1
0
0
218460
When the value in
Var_D20 is larger
...
1
than the value in
Var_D10, M3 turns
ON.
The value in Var_D20
is subtracted from the
...
2
value in Var_D10.
When M3 is ON, the
absolute value
...
3
(two's complement)
is obtained.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Qcpu

Table of Contents