Share on facebook
Share on linkedin
Share on twitter
Share on pinterest
Share on google

Contents

Now that you know how to convert numbers in binary, you should also know a bit how to add numbers. We are focusing mainly on binary, because it is the most important for computer science. This method works mainly as with decimal systems.

Let us see the basics:

0+0=0

0+1=1

1+0=1

1+1= 0 carry one (We can not represent two remember?)

This pretty much tells us any possible combination for addition and subtraction in binary. But we also do it like you learnt in primary school! You take a beautiful table:

1.1 Addition and multiplication in binary and overflow? 1

Overflows

Now you might or might not have noticed something. We can actually overflow. An overflow is when the amount of bits or 1’s and 0’s does not fit anymore in the initial amount of bit’s. So we start with 4 bits + 4 bits and we get a result of 4 bits. Now let us imagine we get a result of 5 bits, depending on the program, sometimes you can not store that value. This leads to an overflow. When you can not represent all bits. So let’s speak about an example:

1111 + 0010 = 10001 right? But if we can not represent all 5 bits , we get the answer 0001 which is way far off from the real value.

This is an actual problem in software programming as the integers in java are stored as 32 bits which is about 4 billion numbers. If you add one to the biggest possible number, you get a result of one. Luckily some compilers will not let you run the code if this happens. And you can also use this to your advantage, in case you make a program that can benefit from this type of overflow.

Multiplication

You guessed it. It is exactly the same as in school as well, in case you learnt this method.

1.1 Addition and multiplication in binary and overflow? 2

Images from: https://www.electronicshub.org/binary-multiplication/ and https://chortle.ccsu.edu/AssemblyTutorial/Chapter-08/ass08_3.html