1 / 27

COMPLEMENTS AND CODING

COMPLEMENTS AND CODING. Complements. Complements are used in digital computers for simplifying the substraction operation and for logical manipulation. There are two type of complements for each base –r system The r’s complement The (r-1)’s complement

Download Presentation

COMPLEMENTS AND CODING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMPLEMENTS AND CODING

  2. Complements Complements are used in digital computers for simplifying the substraction operation and for logical manipulation. There are two type of complements for each base –r system The r’s complement The (r-1)’s complement When the base is 2 means binary no. the complements are (i) 2’s comlement (ii)1’s complement When the base is 10 means decimal no. the complements are (i) 10’s complement (ii) 9’s complement

  3. r’scomplement • Given a positive number N in base r with an integer part of n digits, the r’s compliment of N is defined as rn– N for N ≠ 0 and 0 for N = 0.

  4. Examples • (i)The 10’s complement of (52520)10 is • The number of digits in the number is n = 5. • 105 – 52520 = 47480. • (ii)The 10’s complement of (0.3267)10 is • No integer part, so 10n = 100 = 1. • 1 – 0.3267 = 0.6733 (iii)The 10’s complement of (25.639)10 is 102 – 25.639 = 74.361. (iv)The 2’s complement of (101100)2 is • 26 – 101100 = (1000000 - 101100)2 = 010100. (v)The 2’s complement of (0.0110)2 is (1 – 0.0110)2 = 0.1010.

  5. (r-1)’scomplement • Given a positive number N in base r with an integer part of n digits and a fraction part of m digit, the (r-1)’s compliment of N is defined as rn– r − m – N.

  6. Examples • (i)The 9’s complement of (52520)10 is No fractional part, so 10− m = 100 = 1. • (105 – 1 – 52520) = 99999 – 52520 = 47479 • (ii)The 9’s complement of (0.3267)10 is • No integer part, so 10n = 100 = 1 • (1 – 10− 4 − 0.3267) = 0.9999 – 0.3267 = 0.6732. • (iii)The 9’s complement of (25.639)10 is • (102 – 10− 3– 25.639) = 99.999 – 25.639 = 74.360. • (iv) The 1’s complement of (101100)2 is • (26 – 1) – (101100) = (111111 – 101100)2 = 010011. • (v)The 1’s complement of (0.0110)2 is • (1 – 2− 4)10 – (0.0110)2 = (0.1111 – 0.0110)2 = 0.1001.

  7. Subtraction with r’s Complement • The subtraction of two positive numbers (M - N), both of base r, may be done follows: • Add the minuend M to the r’s complement of the subtrahend N. • Insert the result obtained in step 1 for an end carry: (a). If an end carry occurs, discard it. (b). If an end carry does not occur, take the r’s complement of the number obtained in the step 1 and place a negative sign in front.

  8. Examples • Question 1: Using 10’s complement, subtract 72532 – 3250. • Solution: M = 72532 72532 N = 03250 + 10’s complement of N = 96750 96750 end carry 1 69282 Answer: 69282

  9. Examples • Question 2: Subtract (3250 – 72532)10. . • Solution: M = 03250 03250 N = 72532 + 10’s complement of N = 27468 27468 no carry 30718 Answer: - 69282

  10. Examples • Question 3: Use 2’s complement to perform M – N with given binary numbers. . (a). M = 1010100 1010100 N = 1000100 + 2’s complement of N = 0111100 0111100 end carry 1 0010000 Answer: 10000

  11. Examples (b). M = 1000100 1000100 N = 1010100 + 2’s complement of N = 0101100 0101100 no carry 1110000 Answer: - 10000

  12. Subtraction with (r – 1)’s complement • The subtraction of M – N, both positive numbers in base r, may be calculated in the following in the following manner: • Add the minuend M to the (r -1)’s complement of the subtrahend N. • Inspect the result obtained in the step 1 for an carry. (a). If an end carry occurs, add 1 to te least significant digit (end-around carry). (b). If an end carry does not occur, take the (r-1)’s complement of the number obtained in step 1 and place a negative sign in front.

  13. Examples • Question 1: Using 9’s complement, subtract 72532 – 3250. • Solution: M = 72532 72532 N = 03250 + 9’s complement of N = 96749 96749 end - around carry 1 69281 + Answer: 69282 1 69282

  14. Examples • Question 2: Subtract (3250 – 72532)10. . • Solution: M = 03250 03250 N = 72532 + 9’s complement of N = 27467 27467 no carry 30717 Answer: - 69282

  15. Examples • Question 3: Use 1’s complement to perform M – N with given binary numbers. . (a). M = 1010100 1010100 N = 1000100 + 1’s complement of N = 0111011 0111011 end - around carry 1 0010000 + Answer: 10000 1 0010000

  16. Examples (b). M = 1000100 1000100 N = 1010100 + 1’s complement of N = 0101011 0101011 no carry 1110000 Answer: - 10000

  17. Binary code Digital data is represented, stored and transmitted as group of binary bits. This group is called binary code. The binary code can be used for represent the number as well as alpha numeric letters.

  18. Classification of binary code Binary code Non weighted code Reflective code Sequential code Error detecting and correcting code • Example: 5211 2421 Excess-3 • Example: Gray Excess-3 Five bit BCD • Example: Hamming Parity • Example: 8421 Excess-3 Weighted code BinaryEx: 0s1 • BCDEx: 8421 2421 5211 4221

  19. Binary code decimal (BCD) • We know that decimal, octal, hexadecimal can be represented by binary digit. • Not only numbers but letters and other symbols can be represented by 1s 0s. • Combination of binary digits that represent all these things are called digital codes.

  20. Binary code decimal (BCD)

  21. Gray code • It is called cyclic or reflected code. • In this code each code group does not differ from its neighbour in more than one bit. • This code is used for input and output devices in digital system.

  22. Table of gray code

  23. Conversion from binary to gray code Method: • Write down binary form of the given decimal number. • Write MSB as such. • Then add the binary digit from left to right at the adjacent position. • Discard carry if any. • Write the digit which comes after addition.

  24. Conversion from binary to gray code • Example: Convert 15 into gray code. Solution: (15)10 = (1111)2 We have to convert (1111)2 into gray code Hence the resultant gray code is 1000 for 15. Left most bit 1 1 1 1 + + + 1 0 0 0

  25. Example • Convert (111011)2 into gray code. Solution: • Write the left most bit as such. • Then add the binary digit from left to right at the adjacent position. • Write the digit which comes after addition. Hence the grey code of (111011)2 is 100110. Left most bit 1 1 1 0 1 1 + + + + + 1 0 0 1 1 0

  26. Conversion from grey code to binary code • Method: • Write the given grey code. • Write the left most bit as such. • Add this bit to the second left most bit, write the result, discard carry. • Add this result to the next left most bit diagonally.

  27. Conversion from grey code to binary code • Example: Convert the following grey code into binary code from (1 0 0 0). Solution: Hence the corresponding binary number us (1111)2. We have Left most bit 1 0 0 0 + + + 1 1 1 1

More Related