1 / 35

Basics of Digital Electronics: 1's & 2's Complement

Learn about sign-magnitude, 1's & 2's complement, negative numbers, and binary subtraction in digital electronics. Understand why 2's complement representation is commonly used and how to perform binary subtraction using 2's complement.

dmorissette
Download Presentation

Basics of Digital Electronics: 1's & 2's Complement

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. e – Lesson Module for C-16 Curriculum State Board of Technical Education & Training Andhra Pradesh Year/Semester : III Semester Branch : Electronics and Communication Engg Subject : EC-303, Digital Electronics Topic : Basics of Digital Electronics Sub Topic :1’s &2’s complement of a binary number :2’s complement subtraction Duration : 100 min Prepared by T.MadhaviKumari,Lecturer in ECE Under the guidance of G.V.V.S.Murty, Head of ECE Government Polytechnic for Women , Kakinada C-16-EC-303-1.6and 1.7

  2. Objectives On the completion of this period, you would be able Create negative numbers in the binary number system. Understand how the 2’s complement process can be used to subtract) binary numbers C-16-EC-303-1.6and 1.7

  3. How Binary numbers are represented? • Sign – Magnitude form • 1’s Complement representation • 2’s Complement representation Click here: 1’s &2’s Video C-16-EC-303-1.6and 1.7

  4. +5: 0 0 0 1 0 1 -5: 1 0 0 1 0 1 +ve -ve 5 5 Sign Magnitude • MSB represents sign, remaining bits represent the magnitude • 0 = positive value • 1 = negative value • E.g., 6-bit sign-magnitude representation of +5 and –5: C-16-EC-303-1.6and 1.7

  5. Difficulties with Sign-Magnitude • Two representations of zero • Using 6-bit sign-magnitude… • +0: 000000 • -0: 100000 • Arithmetic is awkward! C-16-EC-303-1.6and 1.7

  6. What is 1’s complement of a binary number? The 1’s complement of a binary number is obtained by changing 0’s to 1’s and 1’s to 0’s For ex: Binary number 1 0 0 0 1’s complement 0 1 1 1 C-16-EC-303-1.6and 1.7

  7. What is 2’s complement of a binary number ? 2’s complement of a binary number is obtained by adding 1 to the 1’s complement of that number. 2’s complement = 1’s complement + 1 This example gives the 2’s complement conversion process ex : Binary number 1 0 1 1 1’s complement 0 1 0 0 + 1 2’s complement 0 1 0 1 C-16-EC-303-1.6and 1.7

  8. Why 2’s Complement representation is most commonly used? • Affords natural arithmetic (no special rules!) • Leads to simple arithmetic circuit that can add and subtract. C-16-EC-303-1.6and 1.7

  9. How To Create A Negative Number? • In digital electronics you cannot simply put a minus sign in front of a number to make it negative. • The 2’s complement process allows you to easily convert a positive number into its negative equivalent and vice&versa • Conversions between positive and negative numbers are easy 2’s C +ve -ve 2’s C C-16-EC-303-1.6and 1.7

  10. This example shows the conversion between positive and negative numbers 0 0 0 1 0 1 +5 1 1 1 0 1 0+ 1 2’s C 1 1 1 0 1 1 -5 0 0 0 1 0 0+ 1 2’s C +5 0 0 0 1 0 1 C-16-EC-303-1.6and 1.7

  11. 2’s Complement Examples Example 1 5 = 00000101  Complement Digits Complement Digits 11111010 -5 =11111011 Add 1 Add 1 Example 2 -13 = 11110011  00001100 +1 +1 13 = 00001101 C-16-EC-303-1.6and 1.7

  12. How the 2’s complement process can be used to subtract binary numbers? subtracting one number from another is the same as making one number negative(2’s complement) and adding. A Minuend B -subtrahend --------------------- A-B = Difference -------------------- A-B=A+(-B) =A+(2’s complement of B) C-16-EC-303-1.6and 1.7

  13. The steps to perform binary subtraction by using 2’s complement are 1. The number of bits in minuend and subtrahend must be same. 2. Add 2’s complement of subtrahend to minuend. 3. If final carry is 1,then the result is positive and which is true,discard the carry. 4. If final carry is 0,then the result is negative and which is in 2’s complement form. To get the true result take 2’s complement of the result Binary Subtraction using 2’s complement C-16-EC-303-1.6and 1.7

  14. Subtraction of a smaller number from a larger number The example in the next slide demonstrates the addition of one positive and one negative number. Again, this is the same a subtracting a positive number from a positive number. In this case the answer happens to be positive C-16-EC-303-1.6and 1.7

  15. Example1 : Subtract 0110 from 1101 by using 2’s complement method. A=1 1 0 1 ………. Minuend B= 0 1 1 0 ……...Subtrahend A-B=A+(-B)=A+(2’s complement of B) 2’s complement of 0110 is 1001 + 1 = 1010 So minuend 1 1 0 1 2’s complement of subtrahend 1 0 1 0 1 0 1 1 1 neglect the carry The difference is 0 1 1 1 C-16-EC-303-1.6and 1.7

  16. Example2: Subtract 1000 from 1100 by using 2’s complement. Minuend = 1100 =A Subtrahend = 1000 =B A-B=A+(-B) =A+(2’s complement of B) Step1: 2’s complement of subtrahend B= -B 1’s complement of 1000 =0111 2’s complement of 1000 =0111+1 =1000 C-16-EC-303-1.6and 1.7

  17. Step2: add 2’s complement of subtrahend to minuend 1 1 0 0 1 0 0 0 1 0 1 0 0 Neglect carry The difference is 0100 C-16-EC-303-1.6and 1.7

  18. Subtraction of a larger number from a smaller number The example in the next slide demonstrates the addition of one positive and one negative number. Again, this is the same a subtracting a positive number from a positive number. In this case the answer happens to be negative. C-16-EC-303-1.6and 1.7

  19. Example 3: Subtract 1101 from 1000 using 2’s complement method. A=minuend=1000 . B= Subtrahend = 1101 A-B = A+ (- B) = A+2’s complement of B 2’s complement of B = 0010 + 1= 0011 minuend=A = 1000 2’s complement of subtrahend(-B) = 0011 1011 No carry. Answer is 2’s complement of 1011 ie , 0100 + 1= - 0101 C-16-EC-303-1.6and 1.7

  20. Example4:Subtract 1110.11 from 101.101 by 2’s complement. Minuend =A = 0101.101 Subtrahend =B =1110.110 • Step1: 2’s complement of subtrahend 1’s complement of subtrahend------ 0001.001 2’s complement =1’s complement+1 1 0001.001 1 0001.010 C-16-EC-303-1.6and 1.7

  21. Step2: add 2’s complement of subtrahend • to minuend • 1 • 0 1 0 1.1 0 1 • 0 0 0 1.0 1 0 • 0 1 1 0.1 1 1 • Step3:No carry.The result is negative and in 2’s • complement form. • Step4:To get the difference take the 2’s • complement and put minus (-) sign. C-16-EC-303-1.6and 1.7

  22. 1’s complement of result 1001.000 2’s complement = 1001.000 + 1 1001.000 1 1001.001 The difference= (-1001.001) C-16-EC-303-1.6and 1.7

  23. 9 + (-5) 4 8th Bit = 0: Answer is Positive Disregard 9th Bit 00000101  11111010 +1 11111011 2’s Complement Process Example5: Subtract decimal 5 from 9 using 2’s complement subtraction Minuend =A=9, Subtrahend=B=5 00001001  + 11111011 1]00000100  C-16-EC-303-1.6and 1.7

  24. (-9) + 5 -4 8th Bit = 1: Answer is Negative 00001001  11110110 +1 11110111 2’s Complement Process Example 6:Subtract decimal 9 from 5 using 2’s complement subtraction Minuend =A=5, Subtrahend=B=9 11110111 + 00000101  11111100  11111100  00000011 +1 00000100 To Check: Perform 2’s Complement On Answer C-16-EC-303-1.6and 1.7

  25. Conclusion • The 1’s complement of a binary number is obtained by changing 0’s to 1’s and 1’s to 0’s • 2’s complement of a binary number is obtained by adding 1 to the 1’s complement of that number. • subtracting one number from another is the same as making one number negative and adding. C-16-EC-303-1.6 and 1.7

  26. Summary We have discussed about • 1’s and 2’s complement of a binary number • Binary subtraction using 2’s complement method C-16-EC-303-1.6and 1.7

  27. Videos Click here:1sand2scomplement Click here:2scomplementsubtraction Click here:2scomplementsubtractionexamples C-16-EC-303-1.6and 1.7

  28. Quiz C-16-EC-303-1.6and 1.7

  29. 1.The 1’s complement of a binary number is obtained by changing a)Each ‘1’ to a ‘0’ b)Each ‘0’ to a ‘1’ c)Each ‘1’ to a ‘0’ and each ‘0’ to a ‘1’ d)None of these. C-16-EC-303-1.6and 1.7

  30. 2 .What is the complement of 1001 a. 0110 b. 1000 c.1011 d. 1111 C-16-EC-303-1.6and 1.7

  31. 3. The advantage of 2’s complement subtraction is a. Subtraction can be done using adder circuit b. Increases Arithmetic hardware c. Decreases Arithmetic software d. Addition made simple C-16-EC-303-1.6and 1.7

  32. 4. Express the 1’s complement of each of the following binary numbers. a) 0010 0011 b) 0100 0101 Answers (a) 1101 1100 (b) 1011 1010 C-16-EC-303-1.6and 1.7 32

  33. 5. What is the 2’s complement of each of these a) 0 0 0 0 1 1 1 1 b) 0 1 0 1 1 0 1 0 Answers (a) 1111 0001 (b) 1010 0110 C-16-EC-303-1.6and 1.7 33

  34. Assignments 1. Use the 2’s complement method to perform the following Subtractions a. 1111 – 1011 b. 110011 – 100101 c. 100101 -110011 d. 1011 -1111 C-16-EC-303-1.6and 1.7

  35. Assignments 2. Use the 2’s complement method to perform subtraction of the following Decimal numbers 54 – 65 b. 68 -32 43 – 68 d. 65 – 54 C-16-EC-303-1.6and 1.7

More Related