Binary Number System
Published: 2022-09-15 21:51:20

 Nowadays, computers use electricity to function, and we know that it can be either turned on or off. This can be represented with the symbols “1” or “0”. This is called binary, and as most of us have already heard, computers function with the binary system. But how does the binary system function itself? Why is it better to use the binary system as the base of all computing systems and operations? Let’s find out together. (P.S. There are other number systems as well such as octal and hexadecimal number systems, but we will only focus on binary and decimal numbers.)

 We are all familiar with the decimal or base ten numerical systems and know that there are ten symbols with which all the other numbers higher than 9 can be represented. We use positional notation to represent all those numbers by adding one more digit to the left of the numbers from 0 to 9. Moreover, that added number’s value is ten times greater than the digit on the right. 

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

 This mechanism applies to binary numbers as well, but here we use only 2 symbols to represent everything else. Here as well each new digit added has a value two times greater than the digit to its left. Binary numbers make the calculations simple, thus computers function with the binary number system. Also, each digit is said to be one bit. 

 Now, there are conversion methods that help us to represent decimal numbers in binary systems and vice versa. We need these conversions as the computer “understands” only binary, while we humans are used to the decimal number system. Converting binary numbers into decimal numbers is easier than it looks. As a first step, assign each digit of the binary number its position starting from 0. The first power should be 2^0, and as we move forward we get 2^1, 2^2, 2^3 … . Then, starting from the right, multiply each digit in the binary number by its corresponding weight based on its position and compute the product. As a result we get the decimal number converted from the binary system. 

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

To convert a decimal number back to a binary number we have to divide it to 2 and write down its reminder. Repeat this until the reminder is 0. Now, arrange the remainders such that the last reminder comes first, followed by the rest in reverse order. See an example down below.

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

 We can add, multiply, subtract and divide in binary pretty much the same way we do it in the decimal number system. First, let’s talk about addition. There are a few rules we need to remember while doing the addition, those are:

1 + 1 = 10
1 + 0 = 1
0 + 1 = 1
0 + 0 = 0

 Knowing these, the addition process becomes much easier. In the example below first consider the last column and add 0 to 0 which gives us 0. Then, add 1to 1, which gives us 10. However, we cannot leave it like that and move the 1 of 10 to the next column just like we do with decimal numbers. After that add 1 to 0, and do not forget the 1 from the previous column as well. As there are no other columns left, write the 1000 as the final result.

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

 As we already know conversion, we can convert these binary numbers and check the equation with decimal numbers. 

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

 Knowing these and decimal multiplication, we can easily do binary multiplications as well. Let’s solve another one together step-by-step. Here, we have to start from the number below the first one and multiply its digits starting from the last one to the digits of the upper number with the same order. The two digits are 1-s so we write 110 and 110 below accordingly to each digit. Knowing how to do addition from before, add those numbers and get the value. 


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

 Let's convert these numbers to decimal again to check if we got it right. 

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