Presentation is loading. Please wait.

Presentation is loading. Please wait.

Complement Theory 1’s and, 2’s complement operation

Similar presentations


Presentation on theme: "Complement Theory 1’s and, 2’s complement operation"— Presentation transcript:

1 Complement Theory 1’s and, 2’s complement operation (r-1)’s and r’s complement 9’s and, 10’s complement operation Binary Codes (BCD Arithematic) Weighted Codes Error Processing Codes Alphanumeric codes.

2 Example 1 Get 1’s complement of 50
Complement Theory Example 1 Get 1’s complement of 50 50 = Complement Digits 

3 1’s Complement Arithmetic (ADD/SUB Method)
Read both the operands Negative operand(s) (if any) is converted into 1’s complement form Add both the numbers If carry is generated (i.e. =1) then the resultant number is positive. Add ONE to the output of setp4, to get the final answer. If carry is not generated then the answer is Negative and available in 1’s complement form. Convert output of step 6 into 1’s complement to get final answer.

4 1’s Complement Theory Example 1 : Subtract 1010 from 1111 using 1’s complement theory. (15-10 Small negative) + 1’s complement 1] + =(5) Carry “1” means the answer is positive . 

5 1’s Complement Theory Example 2 : Subtract 1010 from 1000 using 1’s complement theory. (Large negative 8-10) + 1’s complement 0] Carry “0” means the answer is negative and available in 1’s complement form. = (2)

6 2’s Complement Arithmetic
How to get 2’s complement form Arithmetic operation using 2’s complement theory

7 2’s Complement Arithmetic (How to get 2’s complement form..?)
Example 1 5 = Complement Digits  Add 1 +1 -5 = Example 2 -13 = Complement Digits  Add 1 +1 13 =

8 2’s Complement Arithmetic (Method)
Read both the operands Negative operand (if any) is converted into 2’s complement form Add both the numbers (2’s complement of negative operand with the other one). If carry is generated (i.e. =1) then the resultant number is positive and in original form If carry is not generated(when we have negative operand) then the carry is assumed =0. Carry zero means the resultant number is negative and in a 2’s complement form. Convert the 2’s complement form into the original form.

9 2's Complement Arithmetic
Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics POS + NEG → POS Answer Take the 2’s complement of the negative number and use regular binary 8-bit addition. 9 + (-5) 4  +  Last Bit = 1: Answer is Positive Disregard 9th Bit This example shows the addition of one positive and one negative numbers. Note that this is done in the same way as subtracting a positive number from a positive number. In this case, the answer is positive.  +1 2’s Complement Process Project Lead The Way, Inc. Copyright 2009

10 2's Complement Arithmetic
Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics POS + NEG → NEG Answer Take the 2’s complement of the negative number and use regular 8-bit binary addition. (-9) + 5 -4  +  Last Bit = 0: Answer is Negative . Discard the last bit This slide demonstrates the addition of one positive and one negative number. Again, this is is the same a subtracting a positive number from a positive number. In this case the answer happens to be negative.  +1 To Check: Perform 2’s Complement On Answer  +1 2’s Complement Process Project Lead The Way, Inc. Copyright 2009

11 Verify the logic using following combinations:
1: (10) –(01) 2: (10) –(02) 3: (10) –(05) 4: (10) –(08) 5: (10) –(09) 6: (10) –(10) 7: (210) –(08) 8: (120) –(55) 9: (52) –(18)

12 2’s Complement Arithmetic (Examples)
A+B A B 2’s of B Addition Ans A=10 B=-1 CY =1 So ans is +ve +9 B=-2 CY =1 So ans is +ve +8 B=-5 CY =1 So ans is +ve +5 B=-8 CY =1 So ans is +ve +2 B=-9 CY =1 So ans is +ve +1 B=-10 CY =1 So ans is +ve +0

13 Example: Perform 2’s complement subtraction on 210-08
201= 8= ’s complement of 8 is = Add both the numbers: Carry = 1 means and is positive

14 2’s Complement Arithmetic (Examples on varying number of bits)
Example: Perform 2’s complement arithmetic for (30)-(50) using 1: 6-bit number system 2: 8-bit number system

15 Example: Perform 2’s complement arithmetic for (30)-(50) using:
1: 6-bit number system : 8-bit number system (30)= (-50)= ’s complement (30)= (-50)= ’s complement Add both the numbers Add both the numbers Carry =0 means number is negative and in 2’s compl form = -20 Carry =0 means number is negative and in 2’s compl form = -20

16 (r-1)’s and r’s complement Example of decimal number system
So r becomes 10’s complement And (r-1) becomes 9’s complement

17 How to get (r-1)’s complement of decimal number…?
How do we get (r-1)’s complement …? (r-1)′s i.e. 9’s complement of decimal number can be obtained by ((10n - 1)-number) where n represents the number of digits in given number. Example 1: Find 9’s complement of   (1234)10 9′s complement = (104-1)-1234 = = 8765 How do we get (r)’s complement …? r's i.e. 10’s complement can be obtained by (10n – number) where n represents the number of digits in given number. Example 2: Find 10′s complement = = 8766. We will move to subtraction using them. Remember always the number to be subtracted (negative number) is converted to 9′s or 10′s complement.

18 9’s Complement Arithmetic
Example 1: Get 9’s complement of following numbers (19)10 , (146)10, (4397)10

19 9’s Complement Arithmetic
Example 1: Perform subtraction using 9’s complement on the data set given below. a: , b: c: d: 49-84 We will ADD 93 and 18 9 3 + 1 8 A carry is generated means answer is +ve ADD the carry back to the sum “11”. 1 1 + 1 1 2 06 is negative number, We will get 9’s complement of 06 9 9 - 0 6 9 3 Try for (018) – (006)

20 9’s Complement Arithmetic
Example 2: Perform 9’s complement subtraction on the data set given below. a: , b: c: d: 49-84 We will ADD 76 and 39 7 6 + 3 9 A carry is generated . ADD the carry back to the sum “15”. 1 5 + 1 1 6 23 is negative number, We will get 9’s complement of 23 9 9 - 2 3 7 6 Try for

21 9’s Complement Arithmetic
Example 3: Perform 9’s complement subtraction on the data set given below. a: , b: c: d: 49-84 We will ADD 50 and 34 5 0 + 3 4 0 8 4 A carry is not generated that means answer is Negative. Get 9’s complement of 84 9 9 _ 8 4 1 5 Answer is -15 49 is negative number, We will get 9’s complement of 49 9 9 - 4 9 5 0 Try for

22 9’s Complement Arithmetic
Example 4: Perform 9’s complement subtraction on the data set given below. a: , b: c: d: 49-84 We will ADD 15 and 49 4 9 + 1 5 0 6 4 A carry is not generated that means answer is Negative. Get 9’s complement of 64 9 9 _ 6 4 3 5 Answer is -35 84 is negative number, We will get 9’s complement of 84 9 9 - 8 4 1 5 Try for

23 10’s Complement Arithmetic
Example 1: Perform 10’s complement subtraction on the data set given below. a: , b: c: We will ADD 91 and 24 2 4 + 9 1 1 1 5 09 is negative number, We will get 10’s complement of 09 9 9 - 0 9 9 0 9 1 A carry is generated that means answer is Positive. Answer is +15 Try for

24 10’s Complement Arithmetic
Example 2: Perform 10’s complement subtraction on the data set given below. a: , b: c: We will ADD 68 and 69 6 8 + 6 9 1 3 7 32 is negative number, We will get 10’s complement of 32 9 9 - 3 2 6 7 6 8 A carry is generated that means answer is Positive. Answer is +37 Try for

25 10’s Complement Arithmetic
Example 3: Perform 10’s complement subtraction on the data set given below. a: , b: c: We will ADD 653 and 265 653 + 265 0 918 347 is negative number, We will get 10’s complement of 347 9 9 9 6 5 2 6 5 3 A carry is not generated that means answer is Negative and in 10’s complement form. Get 10’s complement form of 918 9 9 9 -9 1 8 0 8 1 +0 0 1 Ans = -82 Try for

26 BCD Arithmetic

27 Binary Codes Weighted Codes (8421, 5421)
Non Weighted codes (Excess-3 , BCD, Gray/Reflected codes) Error Processing Codes (PARITY Bits, Hamming Codes) Alphanumeric Codes (ASCII, EBCDIC)

28 1: Weighted Codes: Weighted binary codes are those binary codes which obey the positional weight principle. Each position of the number represents a specific weight. 5 4 2 1 7 12 15

29 2: Non-Weighted Codes: 2.1: Excess-3 is a non-weighted coding method. With excess-3, we add 3 to a decimal number before converting it to binary. Example: (0001)2 = (0100)Excess-3 (0010)2 = (0101)Excess-3 2.2: BCD (Binary Coded Decimals) is a non-weighted coding method. Individual decimal digits are converted into equivalent binary bits. Example: (321)2 = ( )BCD (000)2 = ( )BCD (80)2 = ( )BCD (00)2 = ( )BCD

30 2: Non-Weighted Codes: 2.3: Gray Codes: It is also called as Reflected Binary codes. It is generated via getting mirror image of given data. Example : 4 bit Gray codes. 1 1 1 1 1 1 0 1 1 0 1 0 0

31 2: Code Conversion: Converting Binary Codes to Gray codes Method:
Copy MSB of Binary code to MSB of Gray code. Add MSB of Binary with Next MSB of Binary to get next Gray code. Discard the carry Repeat the same process till we get the LSB Example: Convert (0001)2 into Gray code. 0+0= 0 0+0= 0 0+1= 1 1

32 2: Code Conversion: Converting Binary Codes to Gray codes Method:
Copy MSB of Binary code to MSB of Gray code. Add MSB of Binary with Next MSB of Binary to get next Gray code. Discard the carry Repeat the same process till we get the LSB Example: Convert (1011)2 into Gray code. 1+0= 1 0+1= 1 1+1= 0 1 1 1

33 2: Code Conversion: Converting Gray Codes to Binary codes Method:
Copy MSB of Gray code to MSB of Binary code. If next bit of Gray code is “1”, then invert the present binary bit as next bit. If next bit of Gray code is “0” then copy the present binary bit as next bit. Example: Convert (1011) gray into Binary code. 1 1 1

34 BCD Arithmetic: Example 1: (83) +(11) =(94) 1 0 0 0 0 0 1 1
Example 2: (83) +(18) =(101) = (94)


Download ppt "Complement Theory 1’s and, 2’s complement operation"

Similar presentations


Ads by Google