Appendix
G
Numbering
S
ystems
G--9
Numbering Systems
DL105 PLC User Manual, 3rd Edition
Signed vs. Unsigned Integers
So far, we have dealt with unsigned data types only. Now we will deal with signed
data types (negative numbers). The BCD and hexadecimal numbering systems do
not use signed data types.
In order to signify that a number is negative or positive, we must assign a bit to it.
Usually, this is the Most Significant Bit (MSB) as shown in Table 10. For a 16--bit
number, this is bit 15. This means that for 16--bit numbers we have a range of --32767
to 32767.
Bit
#
15 14 13 12 11 10 9
8
7
6
5
4
3
2
1
0
Table 10
There are two ways to encode a negative number: two’s complement and Magnitude
Plus sign. The two methods are not compatible.
The simplest method to represent a negative number is to use one bit of the PLC
word as the sign of a number while the remainder of the word gives its magnitude. It
is general convention to use the most significant bit (MSB) as the sign bit: a 1 will
indicate a negative, and a 0 a positive number. Thus, a 16 bit word allows numbers in
the range
¦
32767. The following tables show a representation of 100 and a
representation of --100 in this format.
Magnitude Plus Sign
Decimal
Binary
100
0000 0000 0110 0100
--100
1000 0000 0110 0100
Table 11
Two’s complement is a bit more complicated. Without getting involved with a full
explanation, a simple formula for two’s complement is to invert the binary and add
one (see Table 12). Basically, 1’s are being changed to 0’s and all 0’s are being
changed to 1, then a 1 is added.
Two’s Compliment
Decimal
Binary
100
0000 0000 0110 0100
--100
1111 1111 1001 1100
Table 12
More information about 2’s complement can be found on the Internet, however most
of the websites deal with 8--bit examples. Two fairly good websites are listed below,
you can also do a search and checkout more websites.
http://www.evergreen.edu/biophysics/technotes/program/2s_comp.htm
http://www.website.masmforum.com/tutorials/fptute/fpuchap2.htm
Содержание DL105
Страница 2: ...DL105 PLC User Manual Manual Number D1 USER M...
Страница 308: ...1B DL105 Error Codes In This Appendix Error Code Table...
Страница 314: ...1C Instruction Execution Times In This Appendix Introduction Instruction Execution Times...
Страница 324: ...1D Special Relays In This Appendix DL105 PLC Special Relays...
Страница 327: ...1E PLC Memory In This Appendix DL105 PLC Memory...
Страница 329: ...1F European Union Directives CE In This Appendix European Union EU Directives Basic EMC Installation Guidelines...