Download presentation
Presentation is loading. Please wait.
Published byJohnathan Stevenson Modified over 9 years ago
1
Number Systems by Dr. Amin Danial Asham
2
References Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan
3
The number systems and digital codes are most often used in in the field of digital computing. First the four number systems most frequently used during input/output address assignment and programming: binary, octal, decimal, and hexadecimal will be introduced. Then, we will discuss the binary coded decimal (BCD) and Gray codes, along with the ASCII character set and several PLC register formats. Since these codes and systems are the foundation of the logic behind PLCs, a basic knowledge of them will help you understand how PLCs work.
4
I.NUMBER SYSTEMS Since a PLC is a computer, it stores information in the form of on or off conditions (1 or 0), referred to as bits. Sometimes bits are used individually and sometimes they are used to represent numerical values. Understanding how these bits can be used to represent numerical values requires an understanding of the binary number system. The number systems usually encountered while using programmable controllers are base 2, base 8, base 10, and base 16. These systems are called binary, octal, decimal, and hexadecimal, respectively.
5
I.NUMBER SYSTEMS (continue) 1.Decimal Number systems The decimal number system, which is the most common to us, was undoubtedly developed because humans have ten fingers and ten toes. The base of the decimal number system is 10. The digits, used in this system are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. The total number of symbols (10) is the same as the base, with the largest- valued symbol being one less than the base (9 is one less than 10). In the decimal system, a place value, or weight, is assigned to each digit position starting from right to left. The first position starting from the right-most position, is position 0, the second is position 1, and so on, up to the last position n
6
I.NUMBER SYSTEMS (continue) 1.Decimal Number systems (continue) The position weights from right to left are 1, 10, 100, 1000, etc. The value of a decimal number is computed by multiplying each digit by the weighted value of its position and then summing the results. This method for computing the value of a number is known as the sum- of-the weights method.
7
I.NUMBER SYSTEMS (continue) 1.Decimal Number systems (continue) In other number systems, the decimal equivalent of any number can be computed by multiplying each digit by its base raised to the power of the digit’s position. Therefore, the sum of N 0 through N n will be the decimal equivalent of the number in base b.
8
I.NUMBER SYSTEMS (continue) 2.Binary Number systems The binary number system uses the number 2 as the base. Thus, the only allowable digits are 0 and 1; there are no 2s, 3s, etc. For devices such as programmable controllers and digital computers, the binary system is the most useful. Most physical elements have only two states: a light bulb is on or off, a valve is open or closed, a switch is on or off, and so on. For devices such as programmable controllers and digital computers, the binary system is the most useful, since it is easier to design machines that distinguish between only two entities, or numbers (i.e., 0 and 1), rather than ten, as in decimal. Digital circuits can distinguish between two voltage levels (e.g., +5 V and 0 V), which makes the binary system very useful for digital applications.
9
I.NUMBER SYSTEMS (continue) 2.Binary Number systems (continue) Expressing binary numbers is accomplished by assigning a weighted value to each position from right to left. The weighted value (decimal equivalent) of a binary number is computed the same way as it is for a decimal number—only instead of being 10 raised to the power of the position, it is 2 raised to the power of the position. For binary, then, the weighted values from right to left are 1, 2, 4, 8, 16, 32, 64, etc., representing positions 0, 1, 2, 3, 4, 5, 6, etc. Let’s calculate the decimal value that is equivalent to the value of the binary number 10110110. Thus, the binary number 10110110 is equivalent to the number 182 in the decimal system.
10
I.NUMBER SYSTEMS (continue) 2.Binary Number systems (continue) Each digit of a binary number is known as a bit. A group of 4 bits is known as a nibble A group of 8 bits is a byte. A group of one or more bytes is called word. A word is basically a fixed-sized group of bits that are handled as a unit by the instruction set and/or hardware of the processor. The least significant bit (LSB), the lowest valued bit. The most significant bit (MSB), the largest valued bit.
11
I.NUMBER SYSTEMS (continue) 2.Binary Number systems (continue) In binary, just like in decimal, we add another digit position once we run out of transitions. So, when we count in binary, the digit following 0 and 1 is 10 (one-zero, not ten), just like when we count 0, 1, 2…9 in decimal, another digit position is added and the next digit is 10 (ten)
12
I.NUMBER SYSTEMS (continue) 3.Octal Number systems Writing a number in binary requires substantially more digits than writing it in decimal. For example, 91 10 equals 1011011 2. Too many binary digits can be difficult to read and write, especially for humans. Therefore, the octal numbering system is often used to represent binary numbers using fewer digits. The octal number system uses the number 8 as its base, with its eight digits being 0, 1, 2, 3, 4, 5, 6, and 7.
13
I.NUMBER SYSTEMS (continue) 3.Octal Number systems (continue) Like all other number systems, each digit in an octal number has a weighted decimal value according to its position. For example, the octal number 1767 8 is equivalent to the decimal number 1015 10 :
14
I.NUMBER SYSTEMS (continue) 3.Octal Number systems (continue) As noted earlier, the octal numbering system is used as a convenient way of writing a binary number. The octal system has a base of 8 (2 3 ), making it possible to represent any binary number in octal by grouping binary bits in groups of three. In this manner, a very large binary number can be easily represented by an octal number with significantly fewer digits. So, a 16-bit binary number can be represented directly by six digits in octal.
15
I.NUMBER SYSTEMS (continue) 4.Hexadecimal Number systems The hexadecimal (hex) number system uses 16 as its base. It consists of 16 digits—the numbers 0 through 9 and the letters A through F (which represent the numbers 10 through 15, respectively) The hexadecimal system is used for the same reason as the octal system, to express binary numbers using fewer digits Since 16=2 4, therefore, the hexadecimal numbering system uses one digit to represent four binary digits (or bits), instead of three as in the octal system.
16
I.NUMBER SYSTEMS (continue) 4.Hexadecimal Number systems (continue) As with the other number systems, hexadecimal numbers can be represented by their decimal equivalents using the sum-of-the-weights method. The decimal values of the letter-represented hex digits A through F are used when computing the decimal equivalent (10 for A, 11 for B, and so on). To convert a hexadecimal number to binary and vice versa, simply write/group the 4-bit binary equivalent of the hex digit for each position. For example:
17
II.NUMBER CONVERSIONS To convert a decimal number to its equivalent in any base, you must perform a series of divisions by the desired base. The conversion process starts by dividing the decimal number by the base. If there is a remainder, it is placed in the least significant digit (right-most) position of the new base number. If there is no remainder, a 0 is placed in least significant digit position. The result of the division is then brought down, and the process is repeated until the final result of the successive divisions is 0.
21
II.NUMBER CONVERSIONS (continue) There is another method, which is a little faster, for computing the binary equivalent of a decimal number. This method employs division by eight, instead of by two, to convert the number first to octal and then to binary from octal (three bits at a time). Example 3: convert the number 145 10 to its binary (base 2) equivalent. Hence The octal equivalent of 145 10 is 221 8, And the binary equivalent of 221 8 equals 010010001 2
22
III.ONE’S AND TWO’S COMPLEMENT The one’s and two’s complements of a binary number are operations used by programmable controllers, as well as computers, to perform internal mathematical calculations. To complement a binary number means to change it to a negative number. This allows the basic arithmetic operations of subtraction to be performed through addition. For example, to subtract the number 20 from the number 40, first complement 20 to obtain –20, and then perform an addition. There are two types of complement: 1’s complement and 2’s complement.
23
III.ONE’S AND TWO’S COMPLEMENT (continue) a)1’s complement Let’s assume that we have a 5-bit binary number that we wish to represent as a negative number. The number is decimal 23, or binary:10111 2 There are two ways to represent this number as a negative number. The first method is to simply place a minus sign in front of the number, as we do with decimal numbers: -(10111) 2 This method is suitable for human but not for digital machines., since the only symbols they use are binary 1s and 0s. First, the one’s complement method places an extra bit (sign bit) in the most significant (left-most) position and lets this bit determine whether the number is positive or negative. The number is positive if the sign bit is 0 and negative if the sign bit is 1.
24
III.ONE’S AND TWO’S COMPLEMENT (continue) a)1’s complement Using the one’s complement method, +23 decimal is represented in binary with the sign bit (0) indicated in bold: 0 10111 2 The negative representation of binary 10111 is obtained by placing a 1 in the most significant bit position and inverting each bit in the number (changing 1s to 0s and 0s to 1s). So, the one’s complement of binary 10111 is: 1 01000 2. If a negative number is given in binary, its one’s complement is obtained in the same fashion. If -15 10 =1 0000 2, therefore, +15=0 1111 2
25
III.ONE’S AND TWO’S COMPLEMENT (continue) b)2’s complement (continue) The two’s complement is similar to the one’s complement in the sense that one extra digit is used to represent the sign The two’s complement computation, however, is slightly different. In the one’s complement, all bits are inverted; but in the two’s complement, each bit, from right to left, is inverted only after the first 1 is detected. For example: +22 10 =0 10110, the two’s complement is: - 22 10 =1 01010 Note that in the negative representation of the number 22, starting from the right, the first digit is a 0, so it is not inverted; the second digit is a 1, so all digits after this one are inverted.
26
III.ONE’S AND TWO’S COMPLEMENT (continue) b)2’s complement (continue) If a negative number is given in two’s complement, its complement (a positive number) is found in the same fashion: -14 10 = 1 10010 2,therefore, +14 10 = 0 01110 2 Another example +1 10 = 0 00001 2,therefore, -1 10 =1 11111 2. The two’s complement of 0 does not really exist, since no first 1 is ever encountered in the number. The two’s complement of 0, then, is 0. The two’s complement is the most common arithmetic method used in computers, as well as programmable controllers.
27
Thanks
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.