Академический Документы
Профессиональный Документы
Культура Документы
Logic Controllers
Third Edition
Frank D. Petruzella
McGraw-Hill
Chapter 3
Number Systems
And Codes
Decimal System
The radix or base of a number system determines
the total number of different symbols or digits
used by the system.
The decimal system has a base of 10.
In the decimal system, 10 unique numbers or
digits ( 0 through 9) are used: the total number
of symbols is the same as the base, and the symbol
with the largest value is 1 less than the base.
Decimal System
The decimal system can be summarized as follows:
Ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Base: 10
Weights: 1, 10, 100, 1000, (powers of base 10)
Decimal System
Weighted value in the decimal system
Binary System
The binary system has a base of 2.
The only allowable digits are 0 and 1
Digital Signal Waveform: with digital circuits it is easy
to distinguish between two voltage levels - +5 V and O V,
which can be related to the binary digits 1 and 0.
Volts
+5
0
Time
Binary System
The binary system can be summarized as follows:
Two digits: 0, 1
Base: 2
Weights: 1, 2, 4, 8, 16, 32, (powers of base 2)
Binary System
Since the binary system uses only
two digits, each position of a binary
number can go through only two
changes, and then a 1 is carried to
the immediate left position.
To express the number in the
binary system requires many
more digits than in the decimal
system.
Decimal
Binary
0000
0001
0010
3
4
5
6
7
8
0011
0100
0101
0110
0111
1000
128
64
32
16
Each
One
16-bit
represents
output
file
thein
word
on
is
orreserved
off
ofeach
one slot
A
wordbit
will
be
created
the table
onlystate
iffor
the
processor
TheMade
column
up of
onsingle
the right
bitslists
grouped
the output
into 16-bit
module
words
address.
output
in the
chassis.
points
are numbered
0 through15.
finds
anpoint.
outputThese
module
residing
in a particular
slot.
c. 13
b. 26
d. 7
c. 4C
b. 1000
d. 00011001
Negative Numbers
In the binary system it is not possible to use positive
and negative symbols to represent the polarity of a
number.
One method is of representing a binary number as
either a positive or negative value is to use an extra digit,
or sign bit, at the MSB of the number. In the sign bit
position, a 0 indicates that the number is positive,
and a 1 indicates a negative number.
Sign
Sign
Bit Magnitude
Bit
Bits
Magnitude
Bits
Decimal
Decimal
Value
Value
Negative Numbers
Another method of expressing a negative number in a
digital system is by using the complement of a binary
number. To represent a negative number in 1's
complement you simply take the numbers magnitude
and flip all the bits (i.e. 1 becomes 0, and 0 becomes 1).
Negative Numbers
The most common way to express a negative binary
number is to show it as a 2s complement number. The
2s complement is the binary number that results
when 1 is added to the 1s complement.
Octal System
The octal numbering system can be summarized
as follows:
Eight digits: 0, 1, 2, 3, 4, 5, 6, 7
Base: 8
Weights: 1, 8, 64, 512, (powers of base 8)
The octal number system is sometimes used
because 8 data bits make up a byte of information
that can be easily addressed by the PLC user or
programmer.
Octal System
The Allen-Bradley PLC-5 family of PLCs uses
the octal numbering systems for addressing
of I/O modules.
I:2/16
O:3/22
Octal System
The digits range from 0 to 7; therefore, numbers
8 and 9 are not allowed!
Converting Octal-to-Binary
Octal is used to handle large binary numbers. One octal
digit is used to express three binary digits.
Hexadecimal System
The hexadecimal (hex) numbering system can
be summarized as follows:
Sixteen digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Base: 16
Weights: 1, 16, 256, (powers of base 16)
The hex numbering system is used in PLCs because
a word of data often consists of 16 data bits, or
two 8-bit bytes.
Hexadecimal-to-Decimal Conversion
To convert a hexadecimal number to its decimal
equivalent, the hexadecimal digits in the columns are
multiplied by the base 16 weight.
Hexadecimal-to-Binary Conversion
Using the hex numbering system allows the status
of a large number of binary bits to be represented
in a small space such as a PLC programming display.
Examples Of Numeric
Values In:
Decimal,
Binary,
BCD,
and Hexadecimal,
Representation
A decimal number
is selected
Gray Code
The Gray code is a special type of binary code that does
not use position weighting.
Gray Code
Gray codes are used with with position encoders for
accurate control of the motion of robots, machine tools,
and servomechanisms.
Typical Encoder Disk
ASCII Code
ASCII stands for American Standard Code for
Information Interchange. It is an alphanumeric code
because it indicates letters as well as numbers.
The keystrokes
on the keyboard
of a computer are
converted directly
into ASCII for
processing by the
computer.
Parity Bit
Some PLC communications systems use a parity bit
to check the accuracy of data transmission. For example,
when data are transferred between PLCs, one of the
binary bits may accidentally change states.
Parity is a system where each character transmitted
contains one additional bit known as a parity bit. The bit
may be binary 0 or binary 1, depending on the number
of 1s and 0s in the character itself.
Two systems of parity are normally used:
odd and even.
Odd parity
means that the
total number of
binary 1 bits in
the character,
including the
parity bit, is odd.
Even parity
means that the
total number of
binary 1 bits in
the character,
including the
parity bit, is even.
Parity Bit
Binary Addition
When adding with binary numbers, there are only
four conditions that can occur.
Binary Addition
When adding larger binary numbers, the resulting
1s are carried into higher-order columns.
Binary Subtraction
To subtract from larger binary numbers, subtract
column by column, borrowing from the adjacent
column when necessary. Remember that when
borrowing from the adjacent column, there are
two digits, i. e., 0 borrow 1 gives 10.
Binary Subtraction
To subtract using the 1s complement:
1. Change the subtrahend to 1s complement
2. Add the two numbers
3. Remove the last carry and add it to the number
1s complement
Binary Multiplication
When multiplying binary numbers, there are only
four conditions that can occur.
0x0=0
0x1=0
1x0=0
1x1=1
Binary Multiplication
To multiply numbers with more than one digit,
form partial products and add them together.
101
x 110
000
101
101
11110
Binary Division
The process for dividing one binary number by
another is the same for both binary and decimal
numbers.
111
10 1110
10
11
10
10
10
00
A = B (A equals B)
A > B (A is greater than B)
A < B (A is less than B)
c. 10111
b. 11100
d. 00111