Welcome to this lecture on unsigned integers in the binary system.
A foundational concept in computer organization, especially when working with low level systems.
And today we will take a deep dive into how binary numbers are added and subtracted, how overflow and
underflow behave fixed with binary systems, and how the architectures handles these operations at the
hardware level.
Now, please keep in mind that I will explain everything slowly and clearly, as if I'm writing each
steps on the board.
Whether you are familiar with this topic or completely new, don't worry.
We will build up the understanding step by step.
And in computing, as you have learned so far, we work with three primary numbers or number systems.
We have the decimal which is base ten.
Or let's use the We have decimal base ten.
Base ten.
Now this is the number system most of us use in our daily life.
It includes digits from 0 to 9.
We have binary which is based two.
Now this is the integral language of computers.
It only uses two digits, zeros and ones.
Every calculation inside the computer is done using binary.
And we have the hexadecimal which is base 16.
The system is used to represent binary in a more compact and readable form.
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
f, which is equals to 15.
Now, even though these numbers systems look different, they can represent the same value.
For example ten in decimal.
Yeah, ten in decimal is not.
Sorry ten in decimal is 1010 in binary and a in hexadecimal.
Now these are just three ways of looking at the same number.
Now you will see these representations frequently in programming, debugging and analyzing data in computer
systems.
Now this table helps you easily translate values between the different number systems.
As you work with more binary and hexadecimal, you will naturally memorize many of this, and you will
often see hexadecimal used when working with memory addresses or machine instructions.
Now, because it's much easier to read and write than long binary sequences like this.
And now what we're going to do is we will add binaries.
Now let's move to the binary addition the process of summing numbers represented in binary.
Now we will use four bit binary numbers in our examples.
That means each number is written using four binary digits.
Now let's represent each number in binary and line them up like a long addition.
So we will add two and four.
So two is what one zero right.
So 0010 and four in binary is 100.
So 0100.
And yeah that's it.
And we also we will also have carry bits carry Pets.
In this case, we have zero carry bits because as you will see, the answer here is zero one again,
one pure one here and pure zero.
And yeah carry bits are 0000.
In this case there are no carry bits generated because the result is less than 16.
Here you can see in the 16th we add one binary.
Here in the eighth we add one binary.
In fourth we add one binary.
This goes on like that.
And here we just basically the generated value result is less than 16 which would require more than
four bits.
Here 16 requires five bits to represent 16 and carry flag is basically zero in a CPU which has which
means no overflow here.
Now this was easy example here.
Now let's do another example.
So what we're going to do we will add four and let's say 14.
And you will see what what will happen here.
So we will have carry bits.
But first we will find four which is 100.
So 0100 and 14 is 1110.
And yeah now let's try adding two larger numbers that will cause an overflow in our four bit space.
And now yeah zero zero.
So there's no carry bit here again zero one.
No zero one is one.
Again.
No carry bit here as well.
But you can see we have two ones which yeah we will add carry bit here and write zero again.
We have the carry bit here.
So you need to translate this bit to here.
And if you translate it to here you will again get zero and still have a carry bit.
Right now if you translate here now you can see that this is basically two which is an incorrect result.
But if we calculate the four and 14 it's basically 18 here right.
Which obviously has five bits.
So I think you are seeing the problem here.
Right.
So 18 in binary is 10010, which needs five bits, but we are only using four bits here, so the extra
bit is dropped somehow.
So this is an what overflow right now.
This is an over.
Now the processor sets the carry flag one.
Now this tells us that the real result doesn't fit in four bits.
And in software, if you want to handle larger numbers, we need to use larger data types like eight
bit or 16 bit integers, or handle the carry manually with logic.
So in this case, what we're going to do is just add another bit here and here.
Put this here right.
And the problem is solved.