Omron CJ - REFERENCE MANUAL 10-2009 Reference Manual page 390

Table of Contents

Advertisement

3. Instructions
Hint
• 2's Complement
A 2's complement is the value obtained by subtracting each binary digit from 1 and adding one to the
result. For example, the 2's complement for 1101 is calculated as follows: 1111 (F hexadecimal) –
1101 (D hexadecimal) + 1 (1 hexadecimal) = 0011 (3 hexadecimal). The 2's complement for 3039
(hexadecimal) is calculated as follows: FFFF (hexadecimal) – 3039 (hexadecimal) + 0001
(hexadecimal) – CFC7 (hexadecimal). Therefore, in case of 4-digit hexadecimal value, the 2's
complement can be calculated as follows: FFFF (hexadecimal) – a (hexadecimal) + 0001
(hexadecimal) = b (hexadecimal). To obtain the true number from the 2's complement b
(hexadecimal): a (hexadecimal) = 10000 (hexadecimal) – b (hexadecimal). For example, to obtain the
true number from the 2's complement CFC7 (hexadecimal): 10000 (hexadecimal) – CFC7 = 3039.
Example 1
FFFF Hex
−)
0001 Hex
FFFE Hex
Negative Flag ON
Carry Flag OFF
Example 2
FFFD Hex
−)
FFFF Hex
FFFE Hex
Negative Flag ON
Carry Flag OFF
20F55A10 - B8A360E3 = -97AE06D3. (Hexadecimal)
In this example, the eight-digit binary value in CIO 121 and CIO 120 is subtracted from the value in CIO
201 and CIO 200, and the result is output in eight-digit binary to D101 and D100. If the result is
negative, the instruction at (2) will be executed, and the actual result will then be output to D101 and
D100.
352
Signed data
Unsigned data
−1
65535
−)
−)
+1
1
−2
65534
Note 1
Note 2
Signed data
Unsigned data
−3
65533
−)
−1
−)
65535
−2
65534
Note 3
Note 4
0.00
CY
Note 1.
Since the Negative Flag is ON, the result (FFFE hex) is
a negative value (2's complement) and is thus −2.
2.
Since the Carry Flag is OFF, the result (FFFE hex) is
an unsigned positive value of 65534.
3.
Since the Negative Flag is ON, the result (FFFE hex) is
a negative value (2's complement) and is thus −2.
4.
Since the Carry Flag is ON, the result (FFFE hex) is a
negative value (2's complement) and becomes −2
when converted to a true value.
RSET
21.00
L
(1)
200
120
D100
L
(2)
#00000000
D100
D100
CY
" "display
SET
21.00
CS/CJ/NSJ Series Instructions Reference Manual (W474)

Advertisement

Table of Contents
loading

Table of Contents