1 / 27

Binary Addition, Subtraction, Complements

Binary number addition and subtraction, subtraction of numbers using complements, signed and unsigned number representation

virginmary
Download Presentation

Binary Addition, Subtraction, Complements

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. Binary Addition, Subtraction and Complements, Mrs. M. Virgin Arockia Mary Asst. Professor Arul Anandar College Karumathur Madurai

  2. Binary Addition

  3. Binary Addition Example 1 • Add 101101 and 1111 • Binary Decimal • ----------------------- ---------------------------- 101101 45 + 001111 + 15 -------------------------------- -------------------------------------- 111100 60

  4. Binary Addition Example 2 • Add 1111011 and 11011 Binary Decimal • ----------------------- ---------------------------- 1111011 123 + 0011011 + 27 -------------------------------- -------------------------------------- 10010110 150

  5. Binary Subtraction

  6. Binary Subtraction Example 1 • Subtract 1111 from 101101 Binary Decimal ----------------------- ---------------------------- 101101 45 - 001111 - 15 -------------------------------- -------------------------------------- 11110 30

  7. Binary Subtraction Example 2 Subtract 11011 from 1111011 Binary Decimal ----------------------- ---------------------------- 1111011 123 - 0011011 - 27 -------------------------------- -------------------------------------- 1100000 96

  8. Reason for Complements • When we are subtracting a Large number from a smaller number, the result obtained will be wrong • Subtract 101101 from 1111 Binary Decimal ----------------------- ---------------------------- 001111 - 15 - 101101 45 -------------------------------- -------------------------------------- Ignore Carry  1 00010 - 30 When we are subtracting a Larger number from smaller number in the binary system the answer we get is not correct. So that to overcome this problem we move to complements

  9. Complements • Computer use complemented numbers or complements to perform subtraction. In the binary number system there are two types of compliments 1’s compliment and 2’s complement. • Similarly, in the decimal number system also there are two types of complements, they are 9’s compliment and 10’s complement.

  10. 9’s complement • The 9’s complement of a decimal number is obtained by subtracting each digit of the number from 9. • Ex:9’s complement of 2 , 36, 234 is 9 99 999 - 2 - 36 - 234 -------------- ----------- --------------- 7 63 765  9’s complement -------------- ----------- ---------------

  11. 10’s complement • The 10’s complement of a number is obtained by adding 1 to the 9’s complement of that number. • Ex:10’s complement of 2 , 36, 234 is 9 99 999 - 2 - 36 - 234 -------------- ----------- --------------- 7 63 765 + 1 + 1 + 1 -------------- ----------- --------------- 8 64 766 10’s complement

  12. Subtraction Using Complements • Complements are used in digital circuits, because it is faster to subtract by adding complements than by performing true subtraction. • Steps: • Adding a number to the 10’s complement of another number is equivalent to subtracting the second number from the first. • First find the 9’s complement of the second number. • Then find out the 10’s complement of that number. • Now add the 10’s complement number with the first number.

  13. Example 1 99 -34 ------ 65 ------- 1 ------- 66 -------- 58 +66 -------- 1 24 ---------- 9’s complement of second number Subtract 34 from 58 58 - 34 --------- 24 ----------- 10’s complement of Second Number Ignore Carry

  14. Subtracting Large number from smaller • In the case of subtracting a larger number from the smaller number, the method is same but the result obtained will be the 10’s complement. To get the correct result,again get the 10’s complement of the result and put a minus(-) sign before it.

  15. Example 1 • (7398) – (9207) = - 1809 • (7398) – (9207) Step 1: Step 2: Step 3: • 9999 7398 9999 • 9207 (-) 793 (+) 8191 (-) • ----------- -------------- ------------- • 0792 8191 1808 • 1 (+) --------------- 1 • ----------- ------------- • 0793 1809 • Now put minus(-) in the answer = -(1809) 9’s Complement 9’s Complement Answer is not Correct -> move to Step 3 10,s Complement 10’s Complement

  16. Example 2 • (3492) – (8342) = - 4850 • (3492) – (8342) Step 1: Step 2: Step 3: • 9999 3492 9999 • 8342 (-) 1658 (+) 5150 (-) • ----------- -------------- ------------- • 1657 5150 4849 • 1 (+) --------------- 1 • ----------- ------------- • 1658 4850 • Now put minus(-) in the answer = -(4850) 9’s Complement 9’s Complement Answer is not Correct -> move to Step 3 10,s Complement 10’s Complement

  17. Subtracting two negative Numbers • If we are subtracting two negative number means we adding the two numbers and put the minus(-) sign. • If we are adding two negative numbers, the method is slightly different. First find the 10’s complement of the two numbers. • You add the 10’s complement of both the numbers, ignore the carry, take the 10’s complement of the result and put minus(-) sign before it.

  18. Example 1 • Subtract -101 from -123  -(123+101) - 224 • First number -123 Step 1: Step 2: Step 3: Step 4: 999 999 877 999 123 (-) 101 (-) 899 (+) 776 (-) --------- ------------ --------------- ------------- 876 898 1 776 223 1 (+) 1 (+) ----------------- 1(+) -------- ------------- ignore Carry --------------- 877 899 224 --------- -------------- ---------------- Now put Minus (-) sign before the number. Answer is –(224)

  19. Example 2 • Subtract -1311 from -6423  -(6423+1311) - 7734 • First number -6423 Step 1: Step 2: Step 3: Step 4: 9999 9999 3577 9999 6423 (-) 1311 (-) 8689 (+) 2266 (-) --------- ------------ --------------- ------------- 3576 8688 1 2266 7733 1 (+) 1 (+) ----------------- 1(+) -------- ------------- ignore Carry --------------- 3577 8689 7734 --------- -------------- ---------------- Now put Minus (-) sign before the number. Answer is –(7734)

  20. 1’s Complement • 1’s complement in the binary system is similar 9’s complement in decimal number system. To get 1’s complement of a number, each bit is subtracted from 1. • Simple way is convert all the 1’s into zero, zero’s into 1’s. Example 1: 101010 010101 Example 2: 0001010 1110101

  21. 2’s Complement • 2’s complement in binary system is similar to the 10’s complement in decimal system. To find the 2’s complement of a number, first get the 1’s complement of the number, then add 1 to the resultant number. • Example 1: Example 2: 1010101 100110 0101010 011001 1 (+) 1 (+) 0101011 011010 1’s Complement 1’s Complement 2’s Complement 2’s Complement

  22. Unsigned and Signed Number Representation • We put (+) or minus (-) sign before the number to represent sign. • To represent a positive number a 0 is placed before the binary number. • To represent a negative number a 1 is placed before the binary number. • Example 1: • + 15  01111 • - 15  11111

  23. Different ways for Negative number

  24. Unsigned Numbers • As we already know, the unsigned numbers don't have any sign for representing negative numbers. So the unsigned numbers are always positive. By default, the decimal number representation is positive. We always assume a positive sign in front of each decimal digit. • When all the bits of the computer word are used to represent the number and no bit is used for sign representation, it is called unsigned representation of numbers.

  25. Signed Numbers The signed numbers are represented in three ways. The signed bit makes two possible representations of zero (positive (0) and negative (1)). There are the following types of representation of signed binary numbers: • Sign-Magnitude formIn this form, a binary number has a bit for a sign symbol. If this bit is set to 1, the number will be negative else the number will be positive if it is set to 0. Apart from this sign-bit, the n-1 bits represent the magnitude of the number. • +7  00111 • -7  10111 MSB is used to represent the sign of the number

  26. 2. 1's ComplementBy inverting each bit of a number, we can obtain the 1's complement of a number. The negative numbers can be represented in the form of 1's complement. In this form, the binary number also has an extra bit for sign representation as a sign-magnitude form. -15 10000 3. 2's ComplementBy inverting each bit of a number and adding plus 1 to its least significant bit, we can obtain the 2's complement of a number. The negative numbers can also be represented in the form of 2's complement. In this form, the binary number also has an extra bit for sign representation as a sign-magnitude form. -15 1 0001

More Related