Programming instructions

46
The PLC uses a numbering format known as two’s complement to display
negative numbers. Two’s complement is easy to calculate:
n Change all 1’s to 0’s and all 0’s to 1’s. This new number is known as
the complement.
o Add a 1 to the number
0111 1111 1111 1111 this is 32,767
1000 0000 0000 0000 this is the complement (the sign bit is not included in the
complement but needs to be a 1 for this number to be negative)
+ 1
add the 1
1000 0000 0000 0001 this is –32,767.
1000 0000 0000 0000 is 1 less than –32,767, therefore it is –32,768.
The NEG command can be used to perform a two’s complement on either
16-bit or 32-bit data to change a negative to a positive.
32 BIT NUMBERS
As stated before, integers are 16 bit by default. When certain commands,
to be discussed later, are used, it is possible to have 32 bit numbers.
When this is done, the PLC looks at two 16 bit registers as 1 large
register. Bit 15 is no longer considered as the MSB. The PLC now
considers bit 32 to be the MSB. This allows the PLC to display integers
with the range -2,147,483,648 to 2,147,483,647 (except when using
scientific notation, see below).
When 32 bit instructions are used, it is important to note that the number
occupies both the destination register and the following register. Take this
into account when writing the program because overwriting the second
register can have unpredictable consequence on the data.