Binary numbers
Tags: programming, binary, beginners
Published: 2022-09-15 18:57:10


Have you ever wandered what are binary numbers? I'm quit sure that probably not once you have seen those cool pictures full of 1s and 0s, which are somehow connected with computers.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4kb7302pewus302i8c84.jpg)


Just as we have the decimal system for counting numbers in everyday life, the same way computers use binary system for calculations. So, it's just another system of counting. With binary numbers we can represent numbers from 0 up to 255(yehhh..., they are better than base 10 system). In case of a decimal system computer would have to work harder and longer in order to process things. Fortunately, binary occupies less space and is much more simpler. We can think of binary as a light switch(When the light is on we have 1 and when off 0). Sounds pretty easy, but wait!!!

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwwdquf2hxjkoftoo5ah.jpg)


You need to know how to convert decimal numbers to binary as well the reverse process. Of course you can use automatic converters but it's better to know how to do it ourselves. Here are the steps for decimal to binary convertion:
Step 1: Divide the given decimal number by “2” where it gives the result along with the remainder.

Step 2: If the given decimal number is even, then the result will be whole and it gives the remainder “0”

Step 3: If the given decimal number is odd, then the result is not divided properly and it gives the remainder “1”.

Step 4: By placing all the remainders in order in such a way, the Least Significant Bit (LSB) at the top and Most Significant Bit (MSB) at the bottom, the required binary number will be obtained.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3mm1xz0ja1ra22zx5swm.jpg)


Also, watch this video:https://youtu.be/rsxT4FfRBaM
The process of converting binary to decimal is even simpler, so just watch the video: https://youtu.be/VLflTjd3lWA and you will understand that for example 11100=2^4+2^3+2^2=28

Ok, let's now pass to more complicated topics like binary operations. Basically, it's very similar to decimal operations. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1dmd0kfybhqm79nbuduf.png)
Having the above table in mind you can do addition confidently like this.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wu8qqhvg5w80hgmlyb4b.png)

Note: Remember that 1+1+1=11 or we can say that the sum is 1 and we have 1 carry.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sebafqmx0qrvx747zpwl.png)

Now let's learn a more complicated operations like multiplication. It's very much similar to decimal multiplication. The only difference is that we use 1s and 0s. For multiplication you should remember these 'rules':
There are four rules of binary multiplication which are:
- 0 × 0 = 0
- 0 × 1 = 0
- 1 × 0 = 0
- 1 × 1 = 1

After knowing these super simple rules you only need to multiply each digit of one binary number to each digit of another binary number. And then add them all together to get the final result.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/744s132tb69qfpckv4zz.png)


Ok, I don't wanna disappoint you but it's also essential to know binary subtraction, but don't worry as after doing a couple of exercises it'll surely become easy. Generally, we apply these rules for subtraction:

- 0 - 0 = 0
- 1 - 0 = 1
- 1 - 1 = 0
- 0 - 1 = 1 with a borrow of 1 

Actually, when you borrow 1 the O becomes 10 or 2 and 2-1=1 that's why 0 - 1 = 1

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nkgw7ksn5ph1bolboruv.png)

Knowing this much it pretty much enough!!! You can also have some fundamental understanding of binary division, but there is no need to dive too much into it. The main rules of the binary division include:

- 1÷1 = 1
- 1÷0 = Meaningless
- 0÷1 = 0
- 0÷0 = Meaningless

Just to have a practice let's divide 18 by 3 which gives 6 :



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhgjld5b52a9odhegibt.png)

That's it!!!Now you know how to do basic operations with binary numbers, hence you understand ''computer language'' better. Hope you enjoyed reading this post!