WEBVTT

00:00.360 --> 00:04.040
Welcome to this lecture on unsigned integers in the binary system.

00:04.600 --> 00:10.880
A foundational concept in computer organization, especially when working with low level systems.

00:11.280 --> 00:17.600
And today we will take a deep dive into how binary numbers are added and subtracted, how overflow and

00:17.640 --> 00:26.600
underflow behave fixed with binary systems, and how the architectures handles these operations at the

00:26.760 --> 00:27.720
hardware level.

00:28.400 --> 00:33.960
Now, please keep in mind that I will explain everything slowly and clearly, as if I'm writing each

00:33.960 --> 00:35.240
steps on the board.

00:35.760 --> 00:39.640
Whether you are familiar with this topic or completely new, don't worry.

00:39.680 --> 00:42.960
We will build up the understanding step by step.

00:43.560 --> 00:51.160
And in computing, as you have learned so far, we work with three primary numbers or number systems.

00:51.720 --> 00:54.960
We have the decimal which is base ten.

00:55.560 --> 00:58.770
Or let's use the We have decimal base ten.

00:59.410 --> 01:00.370
Base ten.

01:00.970 --> 01:04.210
Now this is the number system most of us use in our daily life.

01:04.210 --> 01:07.050
It includes digits from 0 to 9.

01:07.770 --> 01:11.330
We have binary which is based two.

01:12.130 --> 01:15.250
Now this is the integral language of computers.

01:15.250 --> 01:19.370
It only uses two digits, zeros and ones.

01:19.930 --> 01:23.570
Every calculation inside the computer is done using binary.

01:24.250 --> 01:28.890
And we have the hexadecimal which is base 16.

01:29.610 --> 01:33.730
The system is used to represent binary in a more compact and readable form.

01:34.210 --> 01:49.330
It uses 16 symbols from nine, from 0 to 9, and A to f where A equals ten, b 11, and so on up to

01:49.370 --> 01:52.490
f, which is equals to 15.

01:53.140 --> 01:58.340
Now, even though these numbers systems look different, they can represent the same value.

01:58.580 --> 02:01.300
For example ten in decimal.

02:02.380 --> 02:06.700
Yeah, ten in decimal is not.

02:07.180 --> 02:17.660
Sorry ten in decimal is 1010 in binary and a in hexadecimal.

02:18.020 --> 02:21.220
Now these are just three ways of looking at the same number.

02:21.420 --> 02:28.140
Now you will see these representations frequently in programming, debugging and analyzing data in computer

02:28.140 --> 02:28.740
systems.

02:29.220 --> 02:35.020
Now this table helps you easily translate values between the different number systems.

02:35.020 --> 02:41.860
As you work with more binary and hexadecimal, you will naturally memorize many of this, and you will

02:41.900 --> 02:47.420
often see hexadecimal used when working with memory addresses or machine instructions.

02:47.460 --> 02:52.990
Now, because it's much easier to read and write than long binary sequences like this.

02:53.590 --> 02:58.350
And now what we're going to do is we will add binaries.

02:58.910 --> 03:05.390
Now let's move to the binary addition the process of summing numbers represented in binary.

03:05.590 --> 03:08.990
Now we will use four bit binary numbers in our examples.

03:09.310 --> 03:13.390
That means each number is written using four binary digits.

03:14.030 --> 03:18.510
Now let's represent each number in binary and line them up like a long addition.

03:18.790 --> 03:21.390
So we will add two and four.

03:22.070 --> 03:26.710
So two is what one zero right.

03:26.950 --> 03:34.510
So 0010 and four in binary is 100.

03:34.870 --> 03:37.630
So 0100.

03:38.230 --> 03:40.110
And yeah that's it.

03:40.710 --> 03:45.930
And we also we will also have carry bits carry Pets.

03:46.410 --> 03:57.290
In this case, we have zero carry bits because as you will see, the answer here is zero one again,

03:57.330 --> 04:00.050
one pure one here and pure zero.

04:00.650 --> 04:03.330
And yeah carry bits are 0000.

04:04.050 --> 04:10.090
In this case there are no carry bits generated because the result is less than 16.

04:10.770 --> 04:15.770
Here you can see in the 16th we add one binary.

04:15.770 --> 04:18.570
Here in the eighth we add one binary.

04:18.610 --> 04:21.010
In fourth we add one binary.

04:21.730 --> 04:22.970
This goes on like that.

04:23.650 --> 04:32.370
And here we just basically the generated value result is less than 16 which would require more than

04:32.370 --> 04:33.090
four bits.

04:33.130 --> 04:46.100
Here 16 requires five bits to represent 16 and carry flag is basically zero in a CPU which has which

04:46.100 --> 04:47.780
means no overflow here.

04:48.340 --> 04:50.500
Now this was easy example here.

04:50.980 --> 04:53.980
Now let's do another example.

04:54.620 --> 04:59.940
So what we're going to do we will add four and let's say 14.

05:00.540 --> 05:02.540
And you will see what what will happen here.

05:02.660 --> 05:04.740
So we will have carry bits.

05:05.380 --> 05:10.900
But first we will find four which is 100.

05:11.060 --> 05:19.820
So 0100 and 14 is 1110.

05:20.500 --> 05:27.540
And yeah now let's try adding two larger numbers that will cause an overflow in our four bit space.

05:28.220 --> 05:31.140
And now yeah zero zero.

05:31.140 --> 05:35.940
So there's no carry bit here again zero one.

05:36.700 --> 05:39.870
No zero one is one.

05:40.030 --> 05:40.670
Again.

05:40.670 --> 05:43.150
No carry bit here as well.

05:43.870 --> 05:52.350
But you can see we have two ones which yeah we will add carry bit here and write zero again.

05:53.030 --> 05:54.590
We have the carry bit here.

05:54.910 --> 05:57.670
So you need to translate this bit to here.

05:58.110 --> 06:04.590
And if you translate it to here you will again get zero and still have a carry bit.

06:05.070 --> 06:15.670
Right now if you translate here now you can see that this is basically two which is an incorrect result.

06:16.310 --> 06:23.630
But if we calculate the four and 14 it's basically 18 here right.

06:24.270 --> 06:26.110
Which obviously has five bits.

06:26.630 --> 06:31.430
So I think you are seeing the problem here.

06:31.430 --> 06:31.870
Right.

06:32.470 --> 06:44.680
So 18 in binary is 10010, which needs five bits, but we are only using four bits here, so the extra

06:44.720 --> 06:47.200
bit is dropped somehow.

06:47.600 --> 06:52.640
So this is an what overflow right now.

06:52.680 --> 06:54.720
This is an over.

06:55.400 --> 06:58.840
Now the processor sets the carry flag one.

06:59.560 --> 07:04.320
Now this tells us that the real result doesn't fit in four bits.

07:04.960 --> 07:11.720
And in software, if you want to handle larger numbers, we need to use larger data types like eight

07:11.760 --> 07:18.720
bit or 16 bit integers, or handle the carry manually with logic.

07:19.040 --> 07:26.960
So in this case, what we're going to do is just add another bit here and here.

07:27.000 --> 07:29.200
Put this here right.

07:29.800 --> 07:31.240
And the problem is solved.
