Sie sind auf Seite 1von 0

Lecture Number Systems MME 486 Fall 2006

1 of 50
Number Systems and Codes
Industrial Control Systems
Fall 2006
Lecture Number Systems MME 486 Fall 2006
2 of 50
Objectives
Identify the commonly used number
systems: Decimal, Binary, Octal,
Hexadecimal, BCD, Gray code
Convert from one numbering or coding
system to another
Define the terms bit, byte, word, LSB, and
MSB
Lecture Number Systems MME 486 Fall 2006
3 of 50
Why Do I Need to Understand
How Data Is Represented?
In order to install, program, maintain, and
troubleshoot todays PLCs, you must
understand the different methods by which
internal data is represented
Lecture Number Systems MME 486 Fall 2006
4 of 50
Number Systems Typically
Used with PLCs
Lecture Number Systems MME 486 Fall 2006
5 of 50
We Use Symbols Called
Numbers to Represent Data
Everyday numbers are decimal, for
example: 1,234
Computers do not understand the words
and numbers humans use
Computers have their own language called
binary
Lecture Number Systems MME 486 Fall 2006
6 of 50
Decimal System
Ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Base (radix): 10
Weights: 1, 10, 100, 1000, (powers of
base 10)
Lecture Number Systems MME 486 Fall 2006
7 of 50
Decimal System
Lecture Number Systems MME 486 Fall 2006
8 of 50
Decimal System
In general, a number with a decimal point is represented by a
series of coefficients:
a
5
a
4
a
3
a
2
a
1
a
0
.a
-1
a
-2
a
-3
The a
j
coefficients range in value from 0 to r-1, where r is the base,
or radix of the number.
The subscript is the place value and power of the radix by which
the coefficient must be multiplied.
In general, a number expressed in a base-r system has coefficients
multiplied by powers of r:
a
n
r
n
+ a
n-1
r
n-1
+.....+ a
2
r
2
+a
1
r+a
0
+a
-1
r
-1
+a
-2
r
-2
+...+a
-m
r
-m
Lecture Number Systems MME 486 Fall 2006
9 of 50
Converting Numbers
from Base r to Decimal
This relationship is used to convert
numbers from base r to decimal.
e.g. (4021.5)
5
= 4 x 5
3
+ 0 x 5
2
+ 2 x 5
1
+1 x 50 + 2 x 5
-1
= (511.4)
10
(11010.11)
2
= 1 x 2
4
+ 1 x 2
3
+ 0 x 2
2
+ 1 x 2
1
+ 0 x 2
0
+ 1 x 2
-1
+ 1 x 2
-2
=(26.75)
10
Lecture Number Systems MME 486 Fall 2006
10 of 50
Binary System
Binary information is also represented in
groups of characters.
A group of BInary digiTs called bits can be
organized into bytes and words.
Binary bits consist of only two characters:
1 and 0
Lecture Number Systems MME 486 Fall 2006
11 of 50
Binary System
Two digits: 0, 1
Base (radix): 2
Weights: 1, 2, 4, 8, 16, 32, (powers of
base 2)
Lecture Number Systems MME 486 Fall 2006
12 of 50
Binary System
Lecture Number Systems MME 486 Fall 2006
13 of 50
Binary System
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
Time
Volts
+5
0
High (H) (1)
Low (L) (0)
Lecture Number Systems MME 486 Fall 2006
14 of 50
Bits-Bytes-Words
Each digit of a binary number is known as
a bit
A group of 8 bits is known as a byte
A group of bits that occupies one or more
storage locations and is treated as a unit is
known as a word
A 16-bit word is made up of two bytes
(Upper and Lower)
Lecture Number Systems MME 486 Fall 2006
15 of 50
Bits-Bytes-Words
The least significant bit (LSB) is the digit
that represents the smallest value.
The most significant bit (MSB) is the digit
that represents the largest value
Lecture Number Systems MME 486 Fall 2006
16 of 50
Bits-Bytes-Words
16-Bit Word
Bit
Upper Byte
MSB
LSB
Lecture Number Systems MME 486 Fall 2006
17 of 50
PLC Processor Memory Size
The 1 K word memory
size shown can store
1,024 words, or 16,380
(1,024 x 16) bits of
information using
16-bit words or 32,768
(1,024 x 32) using
32 bit words.
Lecture Number Systems MME 486 Fall 2006
18 of 50
Computer Memory Representation
The binary system has only two digits and can
be used to represent any quantity that can be
represented in the decimal system
Computer memory is a series of binary 1s and
0s
Lecture Number Systems MME 486 Fall 2006
19 of 50
Sixteen-Bit Binary
Word Bit Weighting
128 64 32 16 8 4 2 1
If we add only those numbers which have a binary 1
in the box under them, we come up with
128+32+8+4+1 which equals 173
Lecture Number Systems MME 486 Fall 2006
20 of 50
Comparison of Decimal
to Binary Numbers
Lecture Number Systems MME 486 Fall 2006
21 of 50
Converting from Decimal to Base r
It was shown that the sum of products could be used to
convert from base r to decimal.
To reverse the process the number is separated into an
integer part and a fraction part and the conversion od
each part is done separately.
This is best shown by an example of converting 47 in
base 10 to binary:
Lecture Number Systems MME 486 Fall 2006
22 of 50
Converting from Decimal to Base r
integer quotient remainder coefficient
47 = 23 + 1 a
0
= 1
2 2
23 = 11 + 1 a
1
= 1
2 2
11 = 5 + 1 a
2
= 1
2 2
5 = 2 + 1 a
3
= 1
2 2
2 = 1 + 0 a
4
= 0
2
1 = 0 + 1 a
5
= 1
2
Answer (47)
10
= (101111)
2
Lecture Number Systems MME 486 Fall 2006
23 of 50
Converting from Decimal to Base r
The division by the desired radix continues until the integer
quotient becomes 0
The coefficients of the desired number are obtained from the remainders
e.g. convert (153)
10
to Octal (Base 8)
153 / 8 = 19 with a remainder of 1
19 / 8 = 2 with a remainder of 3
2 / 8 = 0 with a remainder of 2
Therefore: (153)
10
= (231)
8
Lecture Number Systems MME 486 Fall 2006
24 of 50
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
Lecture Number Systems MME 486 Fall 2006
25 of 50
Negative Numbers
Sign
Bit
Magnitude Bits
Decimal
Value
Lecture Number Systems MME 486 Fall 2006
26 of 50
Octal System
Eight digits: 0, 1, 2, 3, 4, 5, 6, 7
Base (radix): 8
Weights: 1, 8, 64, 512, (powers of
base 8)
Lecture Number Systems MME 486 Fall 2006
27 of 50
Converting Octal To Decimal
As in all other numbering system, each digit in an octal
number has a weighted decimal value according to its
position
Lecture Number Systems MME 486 Fall 2006
28 of 50
Octal Number System
Place Values
Lecture Number Systems MME 486 Fall 2006
29 of 50
Converting Octal-to-Binary
Lecture Number Systems MME 486 Fall 2006
30 of 50
Hexadecimal System
Sixteen digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
A, B, C, D, E, F
Base (radix): 16
Weights: 1, 16, 256, (powers of base
16)
Lecture Number Systems MME 486 Fall 2006
31 of 50
Place Values of Hexadecimal
Lecture Number Systems MME 486 Fall 2006
32 of 50
Hexadecimal-to-Decimal
Conversion
Lecture Number Systems MME 486 Fall 2006
33 of 50
Hexadecimal-to-Binary Conversion
F 1 1 1 1
E 0 1 1 1
D 1 0 1 1
C 0 0 1 1
B 1 1 0 1
A 0 1 0 1
9 1 0 0 1
8 0 0 0 1
7 1 1 1 0
6 0 1 1 0
5 1 0 1 0
4 0 0 1 0
3 1 1 0 0
2 0 1 0 0
1 1 0 0 0
0 0 0 0 0
Binary Hex
Lecture Number Systems MME 486 Fall 2006
34 of 50
Hexadecimal-to-Binary Conversion
Lecture Number Systems MME 486 Fall 2006
35 of 50
BCD (Binary-Coded Decimal)
System
The BCD (Binary-Coded Decimal)
numbering system provides a convenient
way of handling large numbers that need
to be input to or output from a PLC
Thumbwheels and LED displays make use
of BCD number system
BCD uses four digits to represent each
decimal digit
Lecture Number Systems MME 486 Fall 2006
36 of 50
BCD (Binary-Coded Decimal)
System
Lecture Number Systems MME 486 Fall 2006
37 of 50
Four-Digit BCD Thumb-Wheel
Lecture Number Systems MME 486 Fall 2006
38 of 50
Single-Digit BCD Thumb-Wheel
Interfaced to a PLC
Lecture Number Systems MME 486 Fall 2006
39 of 50
A decimal number
is selected
The thumb-wheel
switch outputs the
equivalent 4-bits
of BCD data
Contd
The circuit board
has one connection
for each bits
weight plus a
common
Lecture Number Systems MME 486 Fall 2006
40 of 50
Comparison of BCD to
Decimal and Binary Numbers
Lecture Number Systems MME 486 Fall 2006
41 of 50
Binary-Coded Decimal
Number Bit Patterns
Lecture Number Systems MME 486 Fall 2006
42 of 50
BCD Invalid Codes
Lecture Number Systems MME 486 Fall 2006
43 of 50
Output Module Connected
to Seven-Segment Display
Lecture Number Systems MME 486 Fall 2006
44 of 50
Decimal, Binary
Hexadecimal,
and BCD
Comparisons
Lecture Number Systems MME 486 Fall 2006
45 of 50
Gray Code
The Gray code is a special type of binary code
that does not use position weighting
It is set up so that as we progress from one
number to the next, only one bit changes
For this reason, the Gray code is considered to
be an error-minimizing code
Because only one bit changes at a time, the
speed of transition for the Gray code is
considerably faster than that for codes such as
BCD
Lecture Number Systems MME 486 Fall 2006
46 of 50
Gray Code
Gray codes are used with position encoders for accurate
control of the motion of robots, machine tools, and
servomechanisms
Typical Encoder Disk
The encoder disk is attached to a
rotating shaft and outputs a digital
Gray code signal that is used to
determine the position of the shaft.
Lecture Number Systems MME 486 Fall 2006
47 of 50
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.
Lecture Number Systems MME 486 Fall 2006
48 of 50
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
Lecture Number Systems MME 486 Fall 2006
49 of 50
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
Lecture Number Systems MME 486 Fall 2006
50 of 50
Parity Bit

Das könnte Ihnen auch gefallen