5-79
5 Understanding Programming
CJ2 CPU Unit Software User’s Manual
5-6 Instructions
5
5-6-3 Data Formats
Additional Information
• Complements
Generally the complement of base x refers to a number produced when all digits of a given
number are subtracted from x-1 and then 1 is added to the rightmost digit. (Example: The ten's
complement of 7556 is 9999 − 7556 + 1 = 2444.) A complement is used to express a subtrac-
tion and other functions as an addition.
Example: With 8954 − 7556 = 1398, 8954 + (the ten's complement of 7556) = 8954 + 2444
= 11398. If we ignore the leftmost bit, we get a subtraction result of 1398.
• Two's Complements
A two's complement is a base-two complement. Here, we subtract all digits from 1 (2 − 1 = 1)
and add one.
Example: The two's complement of binary number 1101 is 1111 (F Hex) − 1101 (D Hex) + 1
(1 Hex) = 0011 (3 Hex). The following shows this value expressed in 4-digit hexadecimal.
The two's complement b Hex of a Hex is FFFF Hex − a Hex + 0001 Hex = b Hex. To deter-
mine the two's complement b Hex of “a Hex,” use b Hex = 10000 Hex − a Hex.
Example: to determine the two's complement of 3039 Hex, use 10000 Hex − 3039 Hex =
CFC7 Hex.
Similarly use a Hex = 10000 Hex − b Hex to determine the value a Hex from the two's com-
plement b Hex.
Example: To determine the real value from the two's complement CFC7 Hex use 10000 Hex
− CFC7 Hex = 3039 Hex.
The CJ Series has two instructions: NEG(160)(2'S COMPLEMENT) and NEGL(161) (DOU-
BLE 2'S COMPLEMENT) that can be used to determine the two's complement from the true
number or to determine the true number from the two's complement.