Numbering Systems
· PLC systems operate in binary.
· It is very cumbersome for us humans to look at data/code in binary or octal or even hexadecimal.
Numbering systems we are going to use with their column values.
103 102 101 100
· Decimal Base10 1000 100 10 1
83 82 81 80
· Octal Base8 512 64 8 1
27 26 25 24 23 22 21 20
· Binary Base2 128 64 32 16 8 4 2 1
163 162 161 160
· Hexadecimal Base16 4096 256 16 1
The four numbering systems, related, are shown below.
Denary Octal Binary Hexadecimal
base 10 base 8 base 2 base 16
0 0 0 0
1 1 1 1
2 2 10 2
3 3 11 3
4 4 100 4
5 5 101 5
6 6 110 6
7 7 111 7
8 10 1000 8
9 11 1001 9
10 12 1010 A
11 13 1011 B
12 14 1100 C
13 15 1101 D
14 16 1110 E
15 17 1111 F
16 20 10000 10
17 21 10001 11
… …… …
31 37 11111 1F
32 40 100000 20
… ……… …
255 377 11111111 FF
256 400 100000000 100
Any number in decimal is usually followed by a D. eg 132D.
Any number in hexadecimal is usually followed by a H. eg 3FH.
Any number in octal is usually followed by a O. eg 132O.
Any number in binary is usually followed by a B. eg 10010011B.
Decimal to Binary
The technique is to subtract the largest binary number possible from the decimal value and write down a ‘1’. Then subtract the next largest. If the number is too big and results in a negative value then write down a ‘0’ after the ‘1’ and then try the next number down. Continue this process until the decimal number is reduced to zero.
16 8 4 2 1
Example 27D 27-16 = 11 1
11- 8 = 3 1 1
3 – 4 = -1 1 1 0
3 – 2 = 1 1 1 0 1
1 – 1 = 0 1 1 0 1 1
to represent the number in 8-bit format just add three leading zero’s
00011011B
Binary to Decimal
In effect this is the reverse of the above. Take each binary ‘1’ bit and add its value to all the other binary ‘1’ bit values.
Example 10101011B 128 + 32 + 8 + 2 + 1 = 171D
Decimal to Hexadecimal
This is the same as decimal to binary except we are working in base16.
Example 171D 171/16 = 10 remainder 11
10 is A and 11 is B 171D = ABH
Hexadecimal to Decimal
Again this is just a reversal of the above.
Example E7H = 14x16 + 7 = 231D
Decimal to Octal
This similar to decimal to hexadecimal but taking into account we are working in base 8.
Example 358D
358/64 = 5 remainder 38 5
38/8 = 4 remainder 6 54
6 546O
Example 945D 945/512 = 1 remainder 433 1
433/64 = 6 remainder 49 16
49/8 = 6 remainder 1 1661
1661O
Octal to Decimal
Again this is a reversal of the above
Example 257O = 2x64 + 5x8 + 7 = 175D
Example 6472O = 6x512 + 4x64 + 7x8 + 2 = 3386D
Octal to Binary
There are two ways to do this. The long way which is octal to decimal to binary, or there is the quick way which goes straight from octal to binary. Let’s do the quick way.
The key to this technique is the relationship between the octal and binary numbers. The first octal digit is represented by the first 3 binary digits 0-7. The second octal digit is represented by the next 3 binary digits 8 – 56.
So each octal digit is represented by clusters of 3 binary digits.
Example 473O
Octal 4 7 3
Binary 100 111 011
=100111011B
Example 5216O
Octal 5 2 1 6
Binary 101 010 001 110
=101010001110B
Binary to Octal
Example 10101001B
Add a leading zero to the binary number to get a cluster of 3 on LHS
Binary 010 101 001
Octal 2 5 1
Example 101110111101B
Binary 101 110 111 101
Octal 5 6 7 3
Binary to Hexadecimal
There is a quick way and a slow laborious way to do this. The slow way is to go from binary to decimal to hex. However there is a quicker method which exploits the relationship between the two numbering systems.
Just write the binary number in blocks of 4 and then work out each blocks hex value.
Example 1 0 1 1 1 1 0 1
B D
=BDH
On the right hand side of the dotted line we have 13 decimal, which in Hex is D.
And on the left hand side we have 11decimal which in Hex is B. By joining the two together we get DBH.
Example 10 0 1 0 1 1 1B
Add two leading zero’s to make a group of four
1 0 0 1 0 1 1 1
9 7
= 97H
Hexadecimal to Binary
This is the reverse of the above.
Example 6AH = 6 A
0 1 1 0 1 0 1 0
Example FFH = F F
1 1 1 1 1 1 1 1B
Binary Coded Decimal (BCD)
Binary coded decimal is used to make the interface between the logic world and the human world – things like seven segment displays. Here’s how it works. We can represent any number in pure binary which you are hopefully used to. We can also represent a number in Denary (decimal) which you most certainly are used to.
BCD is representing a binary number in decimal a format.
Example Hund Tens Units
00011011B is Decimal 27 BCD is 0000 0010 0111
01011111B is Decimal 95 BCD is 0000 1001 0101
00100110B is Decimal 38 in BCD is 0000 0011 1000
1001110011B is Decimal 627 in BCD is 0110 0010 0111
111001000B is Decimal 456 in BCD is 0100 0101 0110
1111001100B is Decimal 972 in BCD is 1001 0111 0010
The binary number is converted into BCD using either Integrated circuits or a PLC or a microprocessor. Whatever is used must be able to have enough current at the correct voltage to drive the 7-segment displays (LED or LCD).
Binary
Code
Decimal / Octal / Binary / Hexadecimal150D
352O
10101111B
3CAH
239D
2345O
1011011011B
A5EFH
762D
56234O
110001110011B
4BE3H
Please fill in the following grid for number conversions as a practice session