WEBVTT

00:00.400 --> 00:01.240
Welcome back.

00:01.440 --> 00:07.560
And in this lecture we are going to take a deeper look at subtraction, focusing on entirely on how

00:07.600 --> 00:11.400
borrowing works step by step in decimal numbers.

00:11.440 --> 00:17.000
Now this is important not only because subtraction is fundamental, but also because everything we do

00:17.040 --> 00:22.320
here will directly apply to how subtraction is performed in binary.

00:22.680 --> 00:28.040
Now, computers subtracting binary, but they follow the exact same logical process.

00:28.280 --> 00:30.040
And we are about to see here.

00:30.040 --> 00:36.320
And as always, since we are doing this in a visual lecture, I will go through what to draw on your

00:36.360 --> 00:39.200
notebook to practice on your own.

00:39.880 --> 00:48.960
Now let's reuse our some example numbers that we used previously 67 subtraction 79.

00:49.560 --> 00:56.480
Now let's go digit by digit starting from the right most column from here.

00:57.160 --> 00:57.960
Now this.

00:57.960 --> 01:06.620
As you remember this is ones tens and hundreds and this goes on like that.

01:07.060 --> 01:07.700
Hundreds.

01:07.740 --> 01:08.340
Thousands.

01:08.380 --> 01:09.300
Ten thousands.

01:09.620 --> 01:10.100
Hundreds.

01:10.100 --> 01:10.740
Thousands.

01:11.180 --> 01:14.340
But now we will work with just ones and tens.

01:14.540 --> 01:15.940
Now you have seven.

01:16.220 --> 01:20.260
Subtract nine, which is not possible.

01:20.500 --> 01:24.180
Seven is smaller than nine.

01:24.860 --> 01:25.860
What to do now?

01:26.620 --> 01:36.180
We borrow one one from six which is next digit to the left in the tens place.

01:36.740 --> 01:43.700
When we borrow, that one becomes a ten to add our digit.

01:44.300 --> 01:53.420
So seven becomes 17 minus nine, which becomes eight.

01:54.020 --> 02:01.020
After the borrow, the six we had here in the tens place is now five.

02:01.580 --> 02:07.500
But now we are doing five minus seven again.

02:08.180 --> 02:12.410
It's not possible Since five is less than seven.

02:13.050 --> 02:15.250
So once again we need to borrow.

02:15.730 --> 02:20.050
But this time we don't have a digit to the left to borrow from.

02:20.650 --> 02:22.450
Now in this two digit number.

02:22.930 --> 02:30.810
So we imagine borrowing from zero here or from an implied digit which gives us ten.

02:31.570 --> 02:37.930
And what we will see here 15 minus seven equals eight.

02:38.490 --> 02:42.170
So eight here and eight here.

02:43.050 --> 02:51.770
Now after all the borrowing and the subtraction, we arrive at the digit 88.

02:52.370 --> 02:56.330
But the result needs to be examined carefully.

02:56.610 --> 03:02.770
The value 67 -79 equals eight.

03:02.890 --> 03:06.090
88 is not correct.

03:06.650 --> 03:12.170
The value 8 to 8 here is not the actual result of 67 -79.

03:12.650 --> 03:22.350
It's a number that came out of treating 67 as if it were, as if it were bigger than 79, and forcing

03:22.350 --> 03:25.510
the subtraction to work by borrowing.

03:26.070 --> 03:34.470
In doing so, we completely ignored the most important part of subtraction which number is actually

03:34.670 --> 03:35.270
larger.

03:35.910 --> 03:38.230
But what we do here.

03:38.750 --> 03:42.950
Now we imagine a zero here, one here.

03:43.510 --> 03:47.190
So if we make the six seven.

03:47.790 --> 03:48.390
So what?

03:48.430 --> 03:53.870
500 -88, we get the result.

03:54.630 --> 03:59.310
But that adds another complexity to our arithmetic here.

03:59.710 --> 04:02.310
But it is also a solution.

04:02.910 --> 04:06.870
In this case 12 is the solution.

04:07.390 --> 04:09.710
But we want to get that 12 easily.

04:09.710 --> 04:10.870
There's an easier way.

04:11.630 --> 04:16.110
In the real math we will just change these places here.

04:16.110 --> 04:21.010
So 79 -67.

04:21.650 --> 04:22.330
What now?

04:23.050 --> 04:23.490
Two.

04:23.890 --> 04:24.370
One.

04:25.730 --> 04:26.970
This is positive number.

04:27.650 --> 04:33.490
So the correct result, because we are subtracting a larger number from a smaller number.

04:34.010 --> 04:40.170
So how did we end up with 88 instead of 12.

04:40.170 --> 04:42.730
Which is actually we will just change it to minus.

04:42.730 --> 04:49.570
I will say that we perform the mechanical borrowing without checking which number was bigger.

04:50.170 --> 04:54.650
So yes, the difference in the magnitude is 12.

04:55.170 --> 05:03.050
But our manual borrowing when starting with 67 incorrectly produced 88 here, which as I said, if you

05:03.330 --> 05:11.250
just you remember once tenths and hundredths, if you end here on the left side of six, we have hundreds,

05:11.250 --> 05:11.730
right.

05:11.850 --> 05:21.650
So if you borrow one from the hundreds and 100 minus our result here equals 12 -12.

05:22.250 --> 05:26.480
Again this is just this just adds another complexity to our subtraction.

05:26.480 --> 05:31.080
So we will not use this model in our lecture.

05:31.080 --> 05:32.680
But here is an easier model.

05:32.680 --> 05:40.560
Just change the places with the higher value if you are subtracting higher from less.

05:40.840 --> 05:45.440
And there we are 12 and add just minus here.

05:45.800 --> 05:46.400
That's it.

05:47.120 --> 05:48.640
Then we will write.

05:48.640 --> 05:53.880
The correct final result is -12 here.

05:54.400 --> 05:58.280
Now always compare your numbers before subtracting.

05:58.280 --> 06:03.800
So if the top number is smaller your result will be negative and the borrowing without considering that

06:03.840 --> 06:07.040
will give you a misleading answer.

06:07.200 --> 06:18.120
Which, uh needs another another layer layer of arithmetic here, which is not needed.

06:18.760 --> 06:19.200
Right.

06:19.880 --> 06:27.160
Let's do another example here 60 or 33 -43.

06:27.880 --> 06:30.780
So 33 is less than 43.

06:30.780 --> 06:36.060
So we will change it to three -33 and ten.

06:36.740 --> 06:39.340
And we will just add minus here.

06:40.100 --> 06:41.980
And here we are.

06:42.660 --> 06:44.980
Now this illustrates an important point.

06:45.500 --> 06:48.260
The digits alone don't tell the whole story.

06:48.260 --> 06:52.300
You must always look at the original problem to understand whether your result should be positive or

06:52.300 --> 06:52.900
negative.

06:53.060 --> 07:03.060
In programming and computing, signed and unsigned number representations help enforce this distinction

07:03.100 --> 07:08.060
automatically using flags and bit encoding, which we will explore later.

07:08.700 --> 07:11.460
And this result makes sense.

07:12.060 --> 07:20.380
If you have $67 and someone asks you to give the 79, you are going to be 12 short.

07:20.940 --> 07:24.340
That's what -12 represents in this context.

07:24.340 --> 07:32.700
In programming, the system needs to know this too, which is why things like sign bits and two's complement

07:32.700 --> 07:33.260
exist.

07:33.260 --> 07:36.370
But we will cover this later in this next.

07:36.850 --> 07:42.370
Now, this example emphasizes how subtraction by borrowing focuses on the mechanical part of the operation

07:42.530 --> 07:43.690
while interpreting.

07:43.690 --> 07:49.130
The final result also requires considering which number is bigger, even though we got the negative

07:49.130 --> 07:51.450
result which is expected.

07:51.610 --> 07:55.610
67 is less than 79.

07:56.130 --> 08:03.370
What we really care about here is step by step borrowing process in subtraction.

08:04.010 --> 08:09.610
Borrowing seems like just a classroom trick when you are learning subtraction in school, but in competing,

08:09.610 --> 08:13.410
the logic is at the heart of subtraction.

08:13.410 --> 08:14.650
Circuits work.

08:14.970 --> 08:21.250
When we get into binary subtraction, we will apply this exact same algorithm, which is two digits

08:21.290 --> 08:22.530
zero and one.

08:23.170 --> 08:28.290
And once you understand borrowing, you will also understand how subtraction creates flags in CPU,

08:28.450 --> 08:29.610
just like addition does.

08:29.770 --> 08:35.770
In this next lecture, we will move on to the binary subtraction and you will see how beautifully this

08:35.770 --> 08:36.930
logic carries over.

08:36.970 --> 08:39.170
Let's continue on typhoon and I'm waiting.
