+ All Categories
Home > Documents > Number Systems by Dr. Amin Danial Asham. References Programmable Controllers- Theory and...

Number Systems by Dr. Amin Danial Asham. References Programmable Controllers- Theory and...

Date post: 21-Jan-2016
Category:
Upload: johnathan-stevenson
View: 215 times
Download: 0 times
Share this document with a friend
27
Number Systems by Dr. Amin Danial Asham
Transcript
Page 1: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

Number Systems

by

Dr. Amin Danial Asham

Page 2: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

References

Programmable Controllers-Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

Page 3: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

•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.

Page 4: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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.

Page 5: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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

Page 6: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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.

Page 7: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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 N0 through Nn will be the decimal equivalent of the number in base b.

Page 8: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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.

Page 9: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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 10110110is equivalent to the number 182 in the decimal system.

Page 10: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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 nibbleA 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.

Page 11: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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)

Page 12: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

I. NUMBER SYSTEMS (continue)3. Octal Number systems

Writing a number in binary requires substantially more digits than

writing it in decimal.

For example, 9110 equals 10110112. 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.

Page 13: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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 17678 is equivalent to the decimal number 101510:

Page 14: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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 (23), 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.

Page 15: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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=24, therefore, the hexadecimal numbering system uses one digit to represent four binary digits (or bits), instead of three as in the octal system.

Page 16: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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:

Page 17: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

II. NUMBER CONVERSIONSTo 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.

Page 18: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

II. NUMBER CONVERSIONS (continue)• As a generic example, let’s find the base 5 equivalent of the number Z.

oThe first division (Z5) gives an N1 result and a remainder R1.

oThe remainder R1 becomes the first digit of the base 5 number (the least significant digit). oTo obtain the next base 5 digit, the N1 result is again divided by 5, giving an N2 result and an R2 remainder that becomes the second base 5 digit.

oThis process is repeated until the result of the division (Nn5) is 0, giving the last remainder Rn, which becomes the most significant digit (leftmost digit) of the base 5 number.

Page 19: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

II. NUMBER CONVERSIONS (continue) Example 1: convert the decimal number 3510 to its binary

(base 2) equivalent.

Hence,

Page 20: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

II. NUMBER CONVERSIONS (continue)

Example 2: convert the number 135510 to its hexadecimal (base 16) equivalent.

Hence, , where 1110 is represented by B in hexadecimal system.

Page 21: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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 14510 to its binary (base 2) equivalent.

Hence The octal equivalent of 14510 is 2218,

And the binary equivalent of 2218 equals 0100100012

Page 22: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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.

Page 23: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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:101112

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.

Page 24: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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 101112

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 010002.

If a negative number is given in binary, its one’s complement is obtained in the same fashion. If -1510=1 00002 , therefore, +15=0 11112

Page 25: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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: +2210 =0 10110, the two’s complement is: -2210 =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.

Page 26: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

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: -1410 = 1 100102 ,therefore, +1410 = 0 011102

Another example +110= 0 000012 ,therefore, -110=1 111112.

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.

Page 27: Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.

Thanks


Recommended