Presentation is loading. Please wait.

Presentation is loading. Please wait.

Complements and Codes by Dr. Amin Danial Asham. References  Digital Design 5 th Edition, Morris Mano  Programmable Controllers-Theory and Implementation,

Similar presentations


Presentation on theme: "Complements and Codes by Dr. Amin Danial Asham. References  Digital Design 5 th Edition, Morris Mano  Programmable Controllers-Theory and Implementation,"— Presentation transcript:

1 Complements and Codes by Dr. Amin Danial Asham

2 References  Digital Design 5 th Edition, Morris Mano  Programmable Controllers-Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

3 IV.COMPLEMENTS  Complements are used in digital computers to simplify the subtraction operations and for logical manipulations.  Simplifying operations leads to simpler, less expensive and hence less expensive circuits to implement the operations.  There are to types of complement; radix r’s complement and diminished radix (r-1)’s complement.  Therefore for binary system we have 2’s complement and 1’s complement and similarly for decimal system we have 10’s complement and 9’s complement.  The concept is applied to any number system.

4

5

6 The 10’s complement of 150 is 1000-150=850

7 The 2’s complement of 1101100 is 0010100

8 III.COMPLEMENTS (continue)  Notes If the original number contains a radix point, the point should be removed temporary in order to obtain the r's or (r - 1)'s complement. The radix point is then restored to the complemented number in the same relative position. The complement of the complement gives the original value of the number.

9 M-N= 72532 – 3250=72532-03250=72532+96750 M-N=1010100-1000011=10110100+0111101

10 M-N=03250-72532 =03250+27468 Where 30718 is the 10’s complement of -69282 M-N= 1000011-1010100=1000011+0101100

11 Positive result IV.COMPLEMENTS (continue) 3.Subtraction with Complements (continue)  The diminished radix complement can be used to convert subtraction to addition in a similar way of radix complement.  Since the diminished radix complement is less by one than the radix complement, therefore after discarding the end carry one must be added to get the sum to get the final result, which is called end-around carry. Negative result

12 IV.COMPLEMENTS (continue) 4.Signed Binary Numbers  Unsigned numbers means we are dealing with non-negative values, while signed number means we are dealing with positive and negative values.  We usually omit the sign symbol when we are dealing with unsigned number such as 9. On the other hand, signed numbers are preceded with a sign symbol such as +9, -6,…etc.  In computer system numbers are represented in binary form and the most left bit is used to indicate the sign in case of signed numbers  For example, if we have a 4-bit register to store unsigned numbers, therefore this register can store numbers from 0000 2 =0 10 to 1111 2 =15 10.  On the other hand, to use this register to store signed numbers, the most left bit is used as indication for the sign and hence the register actually stores positive and negative values of 3 bit numbers since there are one bit reserved for the sign indication.

13

14 V.B INARY C ODES  An important requirement of programmable controllers is communication with various external devices that either supply information to the controller or receive information from the controller. This input/output function involves the transmission, manipulation, and storage of binary data that, at some point, must be interpreted by humans. Although machines can easily handle this binary data, we require that the data be converted to a more interpretable form.  One way of satisfying this requirement is to assign a unique combination of 1s and 0s to each number, letter, or symbol that must be represented. This technique is called binary coding.  In general, there are two categories of codes: a)those that represent numbers only b)and those that represent letters, symbols, and decimal numbers.  Several codes for representing numbers, symbols, and letters are standard throughout the industry. Among the most common are the following: a)ASCII b)BCD c)Gray

15 V.B INARY C ODES(continue) a)ASCII  Alphanumeric codes (which use a combination of letters, symbols, and decimal numbers) are used when information processing equipment, such as printers and displays, must process the alphabet along with numbers and special symbols.  These alphanumeric characters—26 letters (uppercase), 10 numerals (0-9), plus mathematical and punctuation symbols— can be represented using a 6-bit code (i.e., 2 6 = 64 possible characters).  The most common code for alphanumeric representation is ASCII (the American Standard Code for Information Interchange).  An ASCII (pronounced as-kee) code can be 6, 7, or 8 bits.  Although a 6-bit code (64 possible characters) can accommodate the basic alphabet, numbers, and special symbols, standard ASCII character sets use a 7- bit code (2 7 = 128 possible characters), which provides room for lower case and control characters, in addition to the characters already mentioned.  This 7-bit code provides all possible combinations of characters used when communicating with peripherals and interfaces.

16 V.BINARY CODES(continue) a)ASCII (continue)  An 8-bit ASCII code is used when parity check is added to a standard 7-bit code for error-checking purposes (note that all eight bits can still fit in one byte). shows the binary ASCII code representation of the letter Z (132 8 )  A parity bit is an extra to make the total number of 1's either even or odd. Consider the following two characters and their even and odd parity:

17 V.BINARY CODES(continue) a)ASCII (continue) 7-bit ASCII Code

18 V.BINARY CODES(continue) b)BCD  The binary coded decimal (BCD) system was introduced as a convenient way for humans to: i.handle numbers that must be input to digital machines and ii.interpret numbers that are output from machines.  The best solution to this problem was to convert a code readily handled by man (decimal) to a code readily handled by processing equipment (binary). The result was BCD.  The decimal system uses the numbers 0 through 9 as its digits, whereas BCD represents each of these numbers as a 4-bit binary number.  The following table illustrates the relationship between the BCD code and the binary and decimal number systems.

19 V.BINARY CODES(continue) b)BCD (continue)  The BCD representation of a decimal number is obtained by replacing each decimal digit with its BCD equivalent. The BCD representation of decimal 7493 is shown here as an example:  Typical PLC applications of BCD codes include data entry (time, volume, weight, etc.)  via thumbwheel switches (TWS),  data display via seven-segment displays,  input from absolute encoders, and analog input/output instructions

20 V.BINARY CODES(continue) b)GRAY  It is basically a binary code that has been modified in such a way that only one bit changes as the counting number increases.  In standard binary, as many as four digits can change when counting with as few as four binary digits.  This drastic change is seen in the transition from binary 7 to 8  The Gray code is used in applications in which the normal sequence of binary numbers may Produce an error or ambiguity during the transition from one number to the next.  If binary numbers are used. A change. for example from 0111 to 1000 may produce an intermediate erroneous number 1001 if the value of the rightmost bit takes longer to change than do the values of the other three bits. 1-digits change 4-digits change

21 VI.REGISTER WORD FORMATS  As previously mentioned, a digital computer performs all of its internal operations in binary format using 1s and 0s.  Each binary piece of data is a bit. Eight bits make up one byte. Two bytes, or 16 bits, make up one word.  A word is also called a register or location.  Although the data stored in a register is represented by binary 1s and 0s, the format in which this binary data is stored may differ. Generally, data is represented in either straight (non-coded) binary or coded in a code such as binary coded decimal (BCD) format. Byte Word(16-bit register)

22 VI.REGISTER WORD FORMATS 1) BINARY FORMAT  Data stored in binary format can be directly converted to its decimal equivalent without any special restrictions.  In this format, a 16-bit register can represent a maximum value of 65535 10.  The value 65535 10 in binary format all bits are 1.  Hence, 16-bits word may store the statuses of sixteen devices.  If the most significant bit of the register is used as a sign bit, then the maximum decimal value that the 16-bit register can store is +32767 10 or –32767 10 in 2’s complement.

23 Thanks


Download ppt "Complements and Codes by Dr. Amin Danial Asham. References  Digital Design 5 th Edition, Morris Mano  Programmable Controllers-Theory and Implementation,"

Similar presentations


Ads by Google