277 programming appendix a – Omron HOME SECURITY SYSTEM - MOTION SENSOR FQM1-MMA21 User Manual

Page 300

Advertising
background image

277

Programming

Appendix A

Negative Numbers: A value is negative if the leftmost bit is 1 (ON). In 4-digit hexadecimal, this is
expressed as 8000 to FFFF hex. The absolute of the negative value (decimal) is expressed as a two’s
complement.

Example: To treat –19 in decimal as signed binary, 0013 hex (the absolute value of 19) is subtracted
from FFFF hex and then 0001 hex is added to yield FFED hex.

Complements
Generally the complement of base x refers to a number produced when all digits of a given number are sub-
tracted 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 subtraction 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 the 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 determine the two’s comple-
ment 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 complement b hex.

Example: To determine the real value from the two’s complement CFC7 hex, use 10000 hex – CFC7 hex =
3039 hex.

Two instructions, NEG(160)(2’S COMPLEMENT) and NEGL(161) (DOUBLE 2’S COMPLEMENT), can be
used to determine the two’s complement from the true number or to determine the true number from the two’s
complement.

F

F

F

F

1111

1111

1111

1111

0

0

1

3

0000

0000

0001

0011

−)

F

F

E

C

1111

1111

1110

1100

0

0

0

1

0000

0000

0000

0001

+)

F

F

E

D

1111

1111

1110

1101

True number

Two's complement

Advertising