Number Systems
Before we get too far ahead of ourselves, let's take a look at the various number systems used by PLCs.
Many number systems are used by PLCs. Binary and Binary Coded Decimal are popular while octal and hexadecimal systems are also common.
Let's look at each:
As we do, consider the following formula (Math again!):
As we do, consider the following formula (Math again!):
Nbase= Ddigit * R^unit + .... D1R^1 + D0R^0
where D=the value of the digit and R= # of digit symbols used in the given number system.
The "*" means multiplication. ( 5 * 10 = 50)
The "^" means "to the power of".
As you'll recall any number raised to the power of 0 is 1. 10^1=10, 10^2 is 10x10=100, 10^3 is 10x10x10=1000, 10^4 is 10x10x10x10=10000...
The "*" means multiplication. ( 5 * 10 = 50)
The "^" means "to the power of".
As you'll recall any number raised to the power of 0 is 1. 10^1=10, 10^2 is 10x10=100, 10^3 is 10x10x10=1000, 10^4 is 10x10x10x10=10000...
This lets us convert from any number system back into decimal. Huh? Read on...
- Decimal- This is the numbering system we use in everyday life. (well most of us do anyway!) We can think of this as base 10 counting. It can be called as base 10 because each digit can have 10 different states. (i.e. 0-9) Since this is not easy to implement in an electronic system it is seldom, if ever, used. If we use the formula above we can find out what the number 456 is. From the formula:
Nbase= Ddigit * R^unit + .... D1R^1 + D0R^0
we have (since we're doing base 10, R=10)
N10= D410^2 + D510^1 + D610^0 = 4*100 + 5*10 + 6* = 400 + 50 + 6 = 456.
- Binary- This is the numbering system computers and PLCs use. It was far easier to design a system in which only 2 numbers (0 and 1) are manipulated (i.e. used).
The binary system uses the same basic principles as the decimal system. In decimal we had 10 digits. (0-9) In binary we only have 2 digits (0 and 1). In decimal we count: 0,1,2,3,4,5,6,7,8,9, and instead of going back to zero, we start a new digit and then start from 0 in the original digit location.
In other words, we start by placing a 1 in the second digit location and begin counting again in the original location like this 10,11,12,13, ... When again we hit 9, we increment the second digit and start counting from 0 again in the original digit location. Like 20,21,22,23.... of course this keeps repeating. And when we run out of digits in the second digit location we create a third digit and again start from scratch.(i.e. 99, 100, 101, 102...)
Binary works the same way. We start with 0 then 1. Since there is no 2 in binary we must create a new digit.
Therefore we have 0, 1, 10, 11 and again we run out of room. Then we create another digit like 100, 101, 110, 111. Again we ran out of room so we add another digit... Do you get the idea?
The general conversion formula may clear things up:
Nbase= Ddigit * R^unit + .... D1R^1 + D0R^0.
Since we're now doing binary or base 2, R=2. Let's try to convert the binary number 1101 back into decimal.
N10= D1 * 2^3 + D1 * 2^2 + D0 * 2^1 + D1 * 2^0 = 1*8 + 1*4 + 0*2 + 1*1 = 8 + 4 +0 +1 = 13 (if you don't see where the 8,4,2, and 1 came from, refer to the table below).
Now we can see that binary 1101 is the same as decimal 13. Try translating binary 111. You should get decimal 7. Try binary 10111. You should get decimal 23.
Here's a simple binary chart for reference. The top row shows powers of 2 while the bottom row shows their equivalent decimal value.
2^15 | 2^14 | 2^13 | 2^12 | 2^11 | 2^10 | 2^9 | 2^8 | 2^7 | 2^6 | 2^5 | 2^4 | 2^3 | 2^2 | 2^1 | 2^0 |
32768 | 16384 | 8192 | 4096 | 2048 | 1024 | 512 | 256 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
- Octal- The binary number system requires a ton of digits to represent a large number. Consider that binary 11111111 is only decimal 255. A decimal number like 1,000,000 ("1 million") would need a lot of binary digits! Plus it's also hard for humans to manipulate such numbers without making mistakes.
Therefore several computer/plc manufacturers started to implement the octal number system.
This system can be thought of as base8 since it consists of 8 digits. (0,1,2,3,4,5,6,7)
So we count like 0,1,2,3,4,5,6,7,10,11,12...17,20,21,22...27,30,...
Using the formula again, we can convert an octal number to decimal quite easily.
Nbase= Ddigit * R^unit + .... D1R^1 + D0R^0
So octal 654 would be: (remember that here R=8)
N10= D6 * 8^2 + D5 * 8^1 + D4 * 8^0 = 6*64 + 5*8 + 4*1 = 384 +40 +4 = 428 (if you don't see where the white 64,8 and 1 came from, refer to the table below).
Now we can see that octal 321 is the same as decimal 209. Try translating octal 76. You should get decimal 62. Try octal 100. You should get decimal 64.
Here's a simple octal chart for your reference. The top row shows powers of 8 while the bottom row shows their equivalent decimal value.
8^7 | 8^6 | 8^5 | 8^4 | 8^3 | 8^2 | 8^1 | 8^0 |
2097152 | 262144 | 32768 | 4096 | 512 | 64 | 8 | 1 |
Lastly, the octal system is a convenient way for us to express or write binary numbers in plc systems. A binary number with a large number of digits can be conveniently written in an octal form with fewer digits. This is because 1 octal digit actually represents 3 binary digits.
Believe me that when we start working with register data or address locations in the advanced chapters it becomes a great way of expressing data. The following chart shows what we're referring to:
1 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 |
1 | 6 | 2 | 3 | 4 | 5 |
From the chart we can see that binary 1110010011100101 is octal 162345. (decimal 58597) As we can see, when we think of registers, it's easier to think in octal than in binary. As you'll soon see though, hexadecimal is the best way to think. (really)
- Hexadecimal-The binary number system requires a ton of digits to represent a large number. The octal system improves upon this. The hexadecimal system is the best solution however, because it allows us to use even less digits. It is therefore the most popular number system used with computers and PLCs. (we should learn each one though)
The hexadecimal system is also referred to as base 16 or just simply hex. As the name base 16 implies, it has 16 digits. The digits are
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.
So we count like
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10,11,12,13,...
1A,1B,1C,1D,1E,1F,20,21... 2A,2B,2C,2D,2E,2F,30...
Using the formula again, we can convert a hex number to decimal quite easily.
Nbase= Ddigit * R^unit + .... D1R^1 + D0R^0
So hex 6A4 would be:(remember here that R=16)
N10= D6 * 16^2 + DA * 16^1 + D4 * 16^0 = 6*256 + A(A=decimal10)*16 + 4*1 = 1536 +160 +4 = 1700 (if you don't see where the 256,16 and 1 came from, refer to the table below)
Now we can see that hex FFF is the same as decimal 4095. Try translating hex 76. You should get decimal 118. Try hex 100. You should get decimal 256.
Here's a simple hex chart for reference. The top row shows powers of 16 while the bottom row shows their equivalent decimal value. Notice that the numbers get large rather quickly!
16^8 | 16^7 | 16^6 | 16^5 | 16^4 | 16^3 | 16^2 | 16^1 | 16^0 |
4294967296 | 268435456 | 16777216 | 1048576 | 65536 | 4096 | 256 | 16 | 1 |
Finally, the hex system is perhaps the most convenient way for us to express or write binary numbers in plc systems. A binary number with a large number of digits can be conveniently written in hex form with fewer digits than octal. This is because 1 hex digit actually represents 4 binary digits.
Believe me that when we start working with register data or address locations in the advanced chapters it becomes the best way of expressing data. The following chart shows what we're referring to:
0 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 1 |
7 | 4 | A | 5 |
From the chart we can see that binary 0111010010100101 is hex 74A5. (decimal 29861) As we can see, when we think of registers, it's far easier to think in hex than in binary or octal.
0 التعليقات:
إرسال تعليق