Addition and Subtraction using 2's Complement Arithmetic | 2s Complement Addition and Subtraction

ALL ABOUT ELECTRONICS
23 Apr 202123:42

Summary

TLDRThis video tutorial from the All About Electronics YouTube channel explains 2's Complement Arithmetic, focusing on how to add and subtract signed binary numbers. It covers various scenarios, including adding two positive numbers, one positive and one negative, and two negative numbers, highlighting potential overflow issues. The video also demonstrates subtraction by converting it to addition of the first number and the 2's complement of the second. Practical examples with 5-bit and 6-bit representations are used to illustrate the process and emphasize the importance of considering the range to avoid invalid results.

Takeaways

  • 📚 The video explains 2's Complement Arithmetic, a method for performing addition and subtraction with signed binary numbers.
  • 🔢 In 2's Complement addition, you add two numbers as usual, ignoring any carry that extends beyond the most significant bit (MSB).
  • 🚫 If a carry occurs beyond the MSB, it indicates a potential overflow condition where the result exceeds the representable range.
  • 💡 The script uses 5-bit signed binary numbers as examples to illustrate the process of addition and the concept of overflow.
  • 🔄 To find the 2's Complement of a number, first invert the bits to get the 1's Complement, then add 1.
  • ➕ When adding two positive numbers, the result should also be positive, indicated by a 0 in the MSB.
  • ➖ When subtracting a number, it is equivalent to adding the 2's Complement of the number being subtracted.
  • 🔄 For negative numbers, the 2's Complement representation is found by inverting the bits from the left after the first '1' is encountered.
  • 📉 Adding two negative numbers should yield a negative result; if the result is positive, it indicates an invalid outcome due to overflow.
  • 🛠️ The script demonstrates that performing arithmetic in a higher bit-width (like using 6 bits instead of 5) can prevent overflow and yield valid results.

Q & A

  • What is 2's Complement Arithmetic?

    -2's Complement Arithmetic is a method used to perform addition and subtraction of signed binary numbers. It allows for the representation of negative numbers in binary form and simplifies the process of arithmetic operations.

  • How is addition performed in 2's Complement form?

    -In 2's Complement form, addition is performed by adding two numbers column by column, similar to unsigned binary addition. Any carry generated after the most significant bit (MSB) is ignored.

  • What is the significance of the MSB in 2's Complement addition?

    -The MSB in 2's Complement addition indicates the sign of the result. If the MSB is 0, the result is positive; if it's 1, the result is negative.

  • What is an overflow in the context of 2's Complement addition?

    -An overflow occurs when the result of a 2's Complement addition operation exceeds the maximum or minimum value that can be represented with a given number of bits.

  • How can you determine if a 2's Complement addition is correct by looking at the sign bits?

    -If the sign bits of the two numbers being added are the same and the sign bit of the result is different, the addition is likely incorrect, indicating a possible overflow or underflow.

  • What is the range of numbers that can be represented in a 5-bit 2's Complement form?

    -In a 5-bit 2's Complement form, the range of numbers that can be represented is from -16 to +15.

  • How do you find the 2's Complement of a binary number?

    -To find the 2's Complement of a binary number, first invert all the bits (0s become 1s and 1s become 0s) to get the 1's Complement, then add 1 to the least significant bit.

  • How is subtraction performed in 2's Complement form?

    -Subtraction in 2's Complement form is performed by converting the subtrahend to its 2's Complement and then adding it to the minuend.

  • What is the result of adding two negative numbers in 2's Complement form?

    -When adding two negative numbers in 2's Complement form, the result is also negative, assuming no overflow occurs.

  • Why is it important to consider the range when performing 2's Complement arithmetic?

    -It is important to consider the range in 2's Complement arithmetic to ensure that the result of an operation does not exceed the maximum or minimum values that can be represented with the given number of bits, thus avoiding invalid results or overflow.

Outlines

00:00

📐 Introduction to 2's Complement Arithmetic

This paragraph introduces the concept of 2's complement arithmetic, a method used to perform addition and subtraction of signed binary numbers. It explains that addition in 2's complement is similar to unsigned binary addition, where you simply add the numbers and ignore any carry after the most significant bit (MSB). The paragraph also discusses overflow, which occurs when the result of an addition exceeds the representable range of numbers in a given number of bits. An example using 5-bit signed binary numbers is provided, showing how to add two positive numbers, +6 and +7, and how to interpret the result, including the significance of the MSB indicating the sign of the result.

05:02

🔍 Understanding Overflow with 2's Complement

The second paragraph delves into the specifics of overflow in 2's complement arithmetic using a 5-bit example. It demonstrates what happens when the sum of two positive numbers, +9 and +7, exceeds the maximum representable positive number in 5 bits, resulting in an invalid result. The explanation includes a step-by-step addition of the two numbers in binary and how the final result's MSB indicates an incorrect sign, signifying an overflow. This section reinforces the importance of being aware of the range limits when performing arithmetic operations in 2's complement form.

10:07

🤔 Adding Positive and Negative Numbers in 2's Complement

This paragraph explores the scenario where one number is positive and the other is negative in 2's complement arithmetic. It uses the example of adding +13 and -6, explaining how to find the 2's complement of a negative number and then perform the addition. The summary highlights the process of adding the two numbers, taking into account the carry bits, and interpreting the result based on the MSB. It also contrasts this with the scenario where the negative number is greater in magnitude than the positive number, using the example of adding -15 and +9, and how the result indicates a negative number.

15:11

🔄 Adding Two Negative Numbers in 2's Complement

The fourth paragraph focuses on the addition of two negative numbers in 2's complement form. It provides an example with -8 and -4, showing how to represent these numbers in 5-bit 2's complement form and then perform the addition. The explanation includes the step-by-step addition process, the handling of carry bits, and the interpretation of the result based on the MSB. It also discusses the potential for overflow when the result of adding two negative numbers falls outside the representable range, using the example of adding -8 and -9, which exceeds the 5-bit 2's complement range.

20:15

➖ Performing Subtraction Using 2's Complement

The final paragraph discusses how to perform subtraction using 2's complement arithmetic. It explains that subtraction can be treated as an addition of the minuend and the 2's complement of the subtrahend. The paragraph provides examples of subtracting both positive and negative numbers, explaining the process of finding the 2's complement and then performing the addition. It emphasizes the importance of considering the range of representable numbers to ensure the result is valid and not an overflow. The summary also mentions that future videos will cover 1's complement arithmetic.

Mindmap

Keywords

💡2's Complement Arithmetic

2's Complement Arithmetic is a method used to perform arithmetic operations on signed binary numbers. It allows for addition and subtraction to be treated similarly to unsigned numbers. In the video, this concept is central as it is used to explain how to add and subtract signed binary numbers. For instance, adding two positive numbers in 2's complement form is demonstrated by adding 6 and 7, resulting in a positive outcome as expected.

💡Sign Bit

The Sign Bit is the most significant bit (MSB) in a binary number that indicates whether the number is positive or negative. In the context of the video, the sign bit is crucial for determining the outcome of arithmetic operations in 2's complement form. A '0' sign bit means the number is positive, while a '1' indicates it is negative.

💡Overflow

Overflow occurs when an arithmetic operation attempts to create a number that is outside the representable range of values for the given number of bits. The video explains overflow using the example of adding two positive numbers, which results in a value that cannot be represented with the available bits, leading to an incorrect sign in the result.

💡Range

Range refers to the set of values that can be represented with a given number of bits using a specific numeral system. In the video, the range of numbers that can be represented in 2's complement form for a 5-bit system is from -16 to +15. This concept is important for understanding when overflow will occur and for interpreting the validity of results.

💡Carry

A Carry is a value that is generated when the sum of bits being added is too large to be represented in a single bit position. In 2's complement addition, any carry generated after the most significant bit is typically ignored. The video mentions this when adding two positive numbers, where the carry is disregarded in the final result.

💡1's Complement

1's Complement is a numeral system where the complement of a number is found by flipping its bits (changing 0s to 1s and vice versa). In the video, 1's complement is mentioned as a step in finding the 2's complement of a number, which is then used for subtraction in 2's complement arithmetic.

💡Addition

Addition in the context of the video refers to the process of adding two binary numbers together. The video explains how to add two numbers in 2's complement form, showing that it is similar to adding unsigned numbers but with the consideration of the sign bit and potential overflow.

💡Subtraction

Subtraction in 2's complement arithmetic is performed by converting the second operand to its 2's complement and then adding it to the first operand. The video script provides an example of subtracting a number by adding its 2's complement to the other number, which simplifies the process.

💡Binary Numbers

Binary numbers are numerical values expressed in base-2 numeral system, which uses only two symbols, 0 and 1. The video's theme revolves around binary numbers, specifically how to handle signed binary numbers using the 2's complement method for addition and subtraction.

💡MSB

MSB stands for Most Significant Bit, which is the leftmost bit in a binary number and often represents the sign in signed binary systems. The video uses MSB to explain how to determine the sign of the result in 2's complement arithmetic and to identify overflow conditions.

💡Invalid Result

An Invalid Result in the video refers to a situation where the outcome of an arithmetic operation does not make sense given the operands. This typically happens due to overflow or when the expected sign of the result does not match the actual sign, such as adding two negative numbers and getting a positive outcome.

Highlights

Introduction to 2's Complement Arithmetic for signed binary numbers.

Explanation of addition in 2's complement form, ignoring carry after the most significant bit.

Discussion on overflow conditions during 2's complement addition.

Example of adding two positive 5-bit signed binary numbers using 2's complement.

Conversion of 2's complement result to decimal equivalent.

Range of numbers representable in 5-bit 2's complement form.

Illustration of overflow using an example of adding two positive numbers exceeding the range.

Method to identify overflow by comparing sign bits before and after addition.

Case study of adding a positive and a negative number in 2's complement.

Procedure to find the 2's complement of a number to represent its negative.

Addition of a positive and a larger negative number, resulting in a negative outcome.

Technique to find the 2's complement of a result to obtain the positive equivalent.

Addition of two negative numbers and the resulting negative outcome within the 2's complement range.

Overflow example with the addition of two negative numbers exceeding the 5-bit 2's complement range.

Subtraction using 2's complement arithmetic, equivalent to adding the 2's complement of the subtrahend.

Detailed example of subtracting a positive number from another using 2's complement.

Final example demonstrating the importance of considering range during 2's complement arithmetic.

Conclusion emphasizing the importance of range in 2's complement arithmetic and预告 of future videos on 1's complement.

Transcripts

play00:06

Hey, friends welcome to the YouTube channel  ALL ABOUT ELECTRONICS. So in this video,  

play00:12

we will learn about the 2's Complement Arithmetic,  and we will see that, how to perform the addition  

play00:17

and the subtraction of the signed binary numbers,  using this 2's complement method. So the addition  

play00:23

in the 2's complement form, is very similar to  the unsigned binary numbers. So just add the  

play00:29

two numbers, and if there is any carry after the  addition, then just ignore it. And in this way,  

play00:36

the result which we are getting is the correct  result, except whenever we get the overflow.  

play00:42

So later on we will see that, when this overflow  condition can occur. But first of all let us see  

play00:48

the different cases that can occur, while adding  the 2 signed numbers in the 2's complement form.  

play00:54

And for understanding let us take 5 - bit  signed binary numbers as an example. So  

play01:00

during the addition, the first case is, when the  both numbers are positive numbers. Let's say,  

play01:06

we want to add this plus 6 and the plus 7 using  the 5 - bits 2's Complement Arithmetic. So first  

play01:13

of all, let us represent this plus 6  and the plus 7 in the 5 - bit form.  

play01:18

So this plus 6 can be represented as 0  0 1 1 0, where this MSB is the sign bit.  

play01:26

Similarly this plus 7 can be represented as 0 0 1  1 1. And as I said, the addition is very similar to  

play01:34

the addition of the two unsigned numbers. That  means we will do the column by column addition.  

play01:40

That means here, this 0 plus 1 is equal to 1,  while this 1 plus 1 is equal to 0. And there  

play01:47

will be a carry of 1. And if we add this 1 plus  1 plus 1, then the result will be equal to 1,  

play01:54

and the 1 will be the carry. So once again, in  this column this 1 plus 0 is equal to 1. And in  

play02:01

the last column, this 0 plus 0 is equal to 0.  That means after the addition, the result is  

play02:08

0 1 1 0 1. So as you can see, here since the MSB  is equal to 0, that means after the addition,  

play02:16

the result is positive. And if we convert into the  decimal equivalent signed number, then it is equal  

play02:22

to plus 13. So in this way, we can perform the  addition of the two positive numbers. Now in the  

play02:30

previous video, we have seen that, using the n -  bits, the range of number, that can be represented  

play02:36

in this 2's complement form, are from minus 2 to  the power n minus 1 to 2 to the power n minus 1  

play02:43

minus 1. So for the 5 - bits, it is in the range  of minus 16 to plus 15. So after the addition,  

play02:51

if the number is out of this range, then we  will get the invalid result. Or it is the case  

play02:56

of the overflow. So through the example, let us  understand the case of the overflow. So let's say,  

play03:03

we want to add the two numbers plus 9 and the plus  7 using the 5 - bits 2's Complement Arithmetic.  

play03:10

So first let us represent this two numbers in a 5  - bit form. So this plus 9 can be represented as 0  

play03:18

1 0 0 1. Similarly this plus 7 can be represented  as 0 0 1 1 1. And if we add these two numbers,  

play03:28

then this 1 plus 1 is equal to 0, with 1 as a  carry. Similarly, this 1 plus 1 is equal to 0, and  

play03:36

the carry is equal to 1. Likewise this 1 plus 1 is  0, and the carry is equal to 1. Once again this 1  

play03:45

plus 1 is 0, and the 1 is the carry. Therefore,  after the addition the number is 1 0 0 0 0.  

play03:54

And after the addition, the result which you are  getting is in fact invalid. The reason is that,  

play04:00

the addition of the plus 9 and the plus 7 is  equal to plus 16. And as you have just seen,  

play04:06

using the 5 - bits, the maximum number which  can be represented in this 2's complement form  

play04:11

is equal to plus 15. Therefore this addition will  be always invalid. And even just by looking at the  

play04:19

binary addition also, we can decide that  whether this addition is correct or not.  

play04:25

So if we just look at the sign bits of this two  number, then it is equal to 0. On the other end,  

play04:31

if you see the sign bit of the result, then it  is equal to 1, which indicates that the number is  

play04:37

negative. Now here, we are adding the two  positive number, therefore the result has to be  

play04:44

positive. Or in other words, after the addition  the MSB of the result should also be equal to 0.  

play04:51

But in this case, the MSB of the result  is equal to 1. Which indicates that,  

play04:56

this result is invalid. That means whenever,  we are adding the two positive numbers,  

play05:02

whose result is beyond the range of this  n-bit 2's Complement representation,  

play05:07

then we will get the invalid result. And it  is the condition of the overflow. All right,  

play05:13

so now let us take the second case, where the  one number is positive, and the other number  

play05:17

is negative. And first let us consider that, this  positive number is greater than negative number.  

play05:25

So let's say, we want to add the plus 13 and the  minus 6 using this 2's Complement Arithmetic.  

play05:32

Now this minus 6 is in fact the 2's complement  of the number plus 6. So in a 5 - bit form,  

play05:38

this plus 6 is equal to 0 0 1 1 0. So if we  just take the 2's complement of this number,  

play05:46

then we will get the minus 6. So in the previous  video, we have already seen the different ways for  

play05:52

finding the 2's complement. The one way is first  of all find the 1's complement of the number,  

play05:57

and then just add 1 to this 1's complement. So  for the 1's complement, just flip all the 0's  

play06:06

with the 1, and 1's with the 0, in the given  number. And then if we just add 1 to that 1's  

play06:11

complement, then the result is 1 1 0 1 0,  which is the 2's complement of the number  

play06:18

plus 6. Or in other words, this is how the minus  6 can be represented in the 2's complement form.  

play06:25

All right, so now this plus 13 can be  represented as 0 1 1 0 1. And as we have seen,  

play06:32

this minus 6 is equal to 1 1 0 1  0. So if we add these two numbers,  

play06:39

then this 1 plus 0 is equal to 1, while similarly,  this 0 plus 1 is equal to 1. In the next column,  

play06:47

this 1 plus 0 is equal to 1, while this 1  plus 1 is equal to 0, with 1 as a carry.  

play06:54

So in the last column, this 1 plus 1 is equal to  0, with 1 as a carry. So here we will ignore this  

play07:02

carry. So now if we see the result, then it is  equal to 0 0 1 1 1. And here as you can see,  

play07:10

the MSB is equal to 0, which indicates that the  number is positive. And if you see the decimal  

play07:17

equivalent, then it is equal to plus 7. So  this is how, we can do the addition of the  

play07:23

one positive number and the one negative number.  So in this case, the positive number was greater  

play07:29

than negative number. Now let us see the second  case, where this negative number is greater  

play07:35

than positive number. So let's say, we want to  add this minus 15 and plus 9. So first of all,  

play07:43

let us find the equivalent representation  of this minus 15 in the 2's complement form.  

play07:48

So in a 5 - bit form, this plus 15 can be  represented as 0 1 1 1 1, and to find the  

play07:55

2's complement, first of all let us take its  1's complement. That means, just by inverting  

play08:01

all the 0's by 1 and 1's by 0, we will get the 1's  complement, which is equal to 1 0 0 0 0. And now,  

play08:10

if we just add 1 to it, then the result is 1 0 0  0 1. So this represents the 2's complement of the  

play08:18

number plus 15. Or in other words, it represents  the minus 15 in the 2's complement form. So now,  

play08:25

we know that, this minus 15 can be represented as  1 0 0 0 1, while this plus 9 can be represented as  

play08:34

0 1 0 0 1. So now if we just add these two  numbers, then this 1 plus 1 is equal to 0, with  

play08:42

1 as a carry. So now this 1 plus 0 is equal to 1,  and in the next column this 0 plus 0 is equal to  

play08:50

0. Similarly in the next column, this 0 plus 1  is equal to 1, while this 1 plus 0 is equal to  

play08:57

1. So here as you can see, this MSB is equal to  1, which indicates that the result is negative.  

play09:06

So this is the correct representation in  a 2's complement form. So if we just take  

play09:11

the 2's complement of this number, then we  will get the corresponding positive number.  

play09:16

Now in the previous video, we have also seen  the easy way of finding the 2's complement.  

play09:22

So starting from the LSB, copy all the bits,  until we encounter the first one. And then after  

play09:28

replace all the 0's by 1 and 1's by 0. That means  if we see the 2's complement of this number,  

play09:35

then it is equal to 0 1 1 0 0 (from right to left) . So until we  encounter the first one, copy all the bits  

play09:43

as it is. And after this first one, replace all  the 0's by 1, and 1's by 0, in the given number.  

play09:51

That means the 2's complement of the number is  equal to 0 0 1 1 0. And its decimal equivalent  

play09:58

is equal to plus 6. Therefore, this number,  corresponds to minus 6. And in fact, which is  

play10:06

our expected result. Right? Because the addition  of the minus 15, in the plus 9, should be equal  

play10:12

to minus 6. So similarly, now let us see the case  when the two numbers are negative. So let's say,  

play10:20

we want to add the two numbers, that is  minus 8, and minus 4. So first of all,  

play10:26

let us represent this minus 8 and the minus 4  in the 2's complement form. So we know that,  

play10:32

the plus 8 in the 5 - bit form, is equal to  0 1 0 0 0. So if you find its 2's complement,  

play10:40

then it is equal to 0 0 0 1 1 (From right to left). That means  starting from the LSB, copy all the bits,  

play10:48

until we encounter the first one. And then after,  replace all the 0's by 1, and 1's by 0, in the  

play10:54

given number. That means the 2's complement  of this plus 8, is equal to 1 1 0 0 0.  

play11:02

Similarly this plus 4 in a 5 - bit form, can be  represented as 0 0 1 0 0. And its 2's complement  

play11:11

is equal to 0 0 1 1 1 (from right to left) . So in this way, we found  the 2's complement representation of this minus 8  

play11:20

and minus 4. So now, let us just add this minus  8 and minus 4. So if you perform the addition,  

play11:29

then this 0 plus 0 is equal to 0, similarly in  the next column this 0 plus 0 is equal to 0.  

play11:36

Then this 0 plus 1 is equal to ,1 while this 1  plus 1 is equal to 0, with 1 as a carry. And in  

play11:43

this last column, this 1 plus 1 plus 1 is equal to  1, with 1 as a carry. So here, we will ignore this  

play11:51

carry bit. So after ignoring the carry bit, if you  see the result, then it is equal to 1 0 1 0 0. So  

play12:00

here as you can see, the MSB is equal to 1, which  indicates that the number after the addition is  

play12:07

negative. And it is in the 2's complement form.  So if we take the 2's complement of the number,  

play12:13

then we will get the corresponding positive  number. So if we just take the 2's complement,  

play12:18

then its 2's complement is equal to 0 0 1 1 0 (from right to left).  And the corresponding decimal number is equal to  

play12:27

plus 12, which indicates that, this number is  equal to minus 12 in the 2's complement form.  

play12:34

That means, this number represents the minus  12 in the 2's complement form. Now here after  

play12:40

the addition of the two negative number, the  result is still within the 2's complement range.  

play12:45

Bcause for a 5 - bit 2's complement form, we have  seen that, the range is from minus 16 to plus 15.  

play12:52

But after the addition, if the result goes beyond  this range, then the condition of overflow will  

play12:58

occur. Or we can say that, in that case the  result is invalid. So let us take one example,  

play13:04

where the addition of the two negative  number goes beyond the 2's complement range.  

play13:10

So let's say, we want to add the two numbers, that  is minus 8 and the minus 9, using the 5 - bits 2's  

play13:16

Complement Arithmetic. Now as we have seen, using  the 5 - bits we can represent the numbers starting  

play13:23

from minus 16 to plus 15 in a 2's complement form.  So if we add the minus 8 and the minus 9 then the  

play13:30

result is equal to minus 17. And as you can see  it is beyond the range of 5 - bit 2's complement  

play13:37

form. That means in this case, if we add these two  numbers, in a 5 - bit form, then we will get the  

play13:43

invalid result. And the same thing, let us also  see that in a 2's complement form. And for that  

play13:50

first of all let us represent this minus 8 and the  minus 9 in a 2's complement form. So we know that,  

play13:56

the plus 8 can be represented as 0 1 0 0 0.  So its 2's complement is equal to 0 0 0 1 1 (from right to left)

play14:07

Similarly this plus 9 can be represented as  0 1 0 0 1. So its 2's complement is equal to 1 1  

play14:17

1 0 1 (from right to left). So in this way, we found the 2's  complement representation of minus 8  

play14:23

and minus 9. So if you try to add these  two numbers, then the result is 1 0 1 1  

play14:31

1. So here, if we just ignore this carry bit, then  the result is 0 1 1 1 1. So as I said earlier,  

play14:40

just by checking the MSBs, we can decide whether  the addition is correct or not. So here if you  

play14:47

see, then the MSB of the two number, is equal  to 1. That means the two numbers are negative.  

play14:53

On the other end, if we see the MSB of the result,  then it is equal to 0. Which indicates that,  

play14:59

the result is positive. Now whenever, we are  adding the two negative numbers, then the result  

play15:04

should also be negative. Right? But here we are  getting the positive result, which indicates that,  

play15:11

this addition is invalid. That means while adding  the two numbers in a n - bit 2's complement form,  

play15:18

we also need to be careful about the  range. All right, so now let's see,  

play15:23

how to perform the subtraction, using the 2's  Complement Arithmetic. So this subtraction in  

play15:28

this 2's complement arithmetic, is very similar  to the addition. Let's say, we want to subtract  

play15:34

the 3 from 5, which is equivalent of saying  the addition of the plus 5 and the minus 3.  

play15:41

So in the 2's complement arithmetic, it is  equal to 5 plus, 2's complement of the number 3.  

play15:48

So we know that, in a 5 bit form, this plus 3 can  be represented as 0 0 0 1 1. So its 2's complement  

play15:57

is equal to 1 0 1 1 1 (from right to left). Which indicates minus 3.  So now to perform the subtraction, we need to add  

play16:08

this minus 3 and plus 5. So this plus 5 can be  represented as 0 0 1 0 1. And as we have seen,  

play16:17

this minus 3 in a 2's complement form, is equal  to 1 1 1 0 1. So if we perform the addition,  

play16:25

then this 1 plus 1 is equal to 0, with 1 as carry.  So in this next column, this 1 plus 0 is equal to  

play16:33

1. So then after, if we move to the next column,  then this 1 plus 1 is 0, with 1 as a carry to  

play16:39

the next column. So once again this 1 plus 1 is  0, with 1 as a carry to the next column. And in  

play16:47

the last column, this 1 plus 1 is 0, with  1 as a carry. So here we will ignore this  

play16:54

carry bit. So after ignoring this carry, if we see  the equivalent number, then it is equal to 0 0 0  

play17:01

1 0. And as you can see, here the MSB is equal to  0. Which indicates that after this addition, or in  

play17:08

other words after the subtraction, the resultant  is positive. And if we see the decimal equivalent,  

play17:15

then it is equal to plus 2. So in this  way, using this 2's complement arithmetic,  

play17:22

we can also perform the subtraction, similar to  the addition. So similarly, let's say we want  

play17:28

to subtract this minus 6 from plus 9. Which is  equivalent of saying the addition of plus 9 with a  

play17:35

2's complement of the number minus 6. Now we know  that, the 2's complement of the negative number is  

play17:42

positive. That means the 2's complement of minus 6  is equal to plus 6. So to perform the subtraction,  

play17:49

we just need to add this plus 9 with plus 6. And  if you see the equivalent number, then it is equal  

play17:56

to 0 1 1 1. And the corresponding decimal  number is equal to plus 15. So in this way,  

play18:05

using this 2's complement arithmetic  it is very easy to perform subtraction,  

play18:09

just like a addition. All right, so now  let's take this last example. So let's say,  

play18:16

we want to subtract these two numbers using this  2's complement arithmetic. And here both numbers  

play18:23

are in a 2's complement form. So let's say  these two numbers are P and Q respectively.  

play18:30

So in a 2's complement arithmetic, this P minus Q  is effectively P plus 2's complement of the number  

play18:37

Q. So first of all, let us find the 2's complement  of the number Q. So if we find the 2's complement,  

play18:45

then it is equal to 1 0 0 1 1. And  effectively it is equal to minus Q.  

play18:52

So now let's add P to this minus Q. So if you  perform the addition, then this 1 plus 1 is 0,  

play19:00

with 1 is a carry to the next column. Then in the  next column, this 1 plus 1 plus 1 is equal to 1,  

play19:07

with 1 as a carry to the next column. So now in  this third column, this 1 plus 0 is equal to 1.  

play19:14

And in the fourth column, this 0 plus 1 is 1,  while in the fifth column this 1 plus 1 is 0,  

play19:21

with 1 as a carry. So if we ignore this carry  bit, then the result is 0 1 1 1 0. Now let's see,  

play19:30

whether our addition is correct or not.  So if you see the MSB of the 2 number,  

play19:35

then it is equal to 1. Which indicates that,  the two numbers are negative. On the other end,  

play19:41

the MSB of the result is equal to 0. So as I said  earlier, when we add the two negative numbers,  

play19:48

then the result has to be negative. That means  the MSB of the result, should also be equal to  

play19:54

1. But in this case, as you can see, it is equal  to 0. Which indicates that, the result is invalid.  

play20:02

So let us understand, why we are getting this  invalid result. And for that, let us find the  

play20:07

decimal equivalent of the given numbers. So  here, both numbers are in a 2's complement form.  

play20:14

And in the first number the MSB is equal to 1.  Which indicates that, the number is negative.  

play20:21

So if we find the 2's complement of the number,  then we will get the equivalent positive number.  

play20:27

That is equal to 1 0 1 0 0 (from right to left). Which corresponds to  plus 5. That means the given number is equal to  

play20:36

minus 5. Likewise the second number is equal to 0  1 1 0 1. And in decimal, it is equal to plus 13.  

play20:48

So here, what we are doing, we are subtracting  this minus 13, from minus 5. And therefore,  

play20:54

the result should be equal to minus 18. But as  we have seen in a 5 - bit 2's complement form,  

play21:00

the range of number that can be represented are  from minus 16 to plus 15. That means this minus  

play21:07

18 is out of the 2's complement range. And  therefore we are getting the invalid result.  

play21:13

But suppose for the same numbers, if we do the  2's complement arithmetic, in a 6 - bit form,  

play21:19

then we will get the correct result.  Because in a 6 - bit representation,  

play21:23

the result is within the given range. So let's  perform the same arithmetic, in a 6 - bit form.  

play21:30

And first of all, let us represent both numbers  in a 6 - bit 2's complement form. So if we try to  

play21:37

represent these numbers, in a 6 - bit form, then  we need to copy the MSB of these two numbers in a  

play21:43

additional bit. So this is how, these two numbers  can be represented in a 6 - bit form. So here, we  

play21:50

have just copied the MSB of this two number in the  additional bit. So by doing so, the number remains  

play21:56

the same. So now, let us find the 2's complement  of this second number. That is equal to 1 1  

play22:05

0 0 1 1 (from right to left). So instead of performing the subtraction,  now we need to add, these two numbers. And if you  

play22:14

try to perform the addition, then it is equal to 1  1 0 1 1 1 0. So if we just ignore this carry bit,  

play22:24

then the result is 1 0 1 1 1 0. And here as you  can see the MSB is equal to 1. Which indicates  

play22:32

that, the number is negative. So if we just take  the 2's complement of that number, then we will  

play22:38

get the corresponding positive number. That is  equal to 0 1 0 0 1 0 (from right to left), which is equal to plus 18.  

play22:48

That means, this number corresponds to minus 18  in a 2's complement representation. So as you  

play22:54

can see, now in a 6 - bit form, we are getting the  correct result. That means, while performing the  

play23:01

addition or the subtraction in this 2's complement  form, we should always be careful about the range.  

play23:07

So these are the few things, which we need to keep  in mind, during the 2's complement arithmetic.  

play23:13

But I hope through the different examples,  you understood how to perform the addition  

play23:17

and the subtraction using this 2's complement  arithmetic. So similarly, in the future videos,  

play23:23

we will see that, how to perform the addition  using the 1's complement arithmetic. So if you  

play23:29

have any question or suggestion, then do let  me know here in the comment section below.  

play23:34

If you like this video, hit the like button  and subscribe the channel for more such videos.

Rate This

5.0 / 5 (0 votes)

الوسوم ذات الصلة
2's ComplementBinary ArithmeticElectronics TutorialSigned BinaryOverflow ConditionMSB SignificanceAddition RulesSubtraction MethodComplement ExamplesRange Consideration
هل تحتاج إلى تلخيص باللغة الإنجليزية؟