The magic explanation of the Binary number system. Arithmetic operations with binary numbers.
Tags: computerscience, understandingcomputers, machinelearning, introduction
Published: 2022-09-14 12:39:40

## Introduction

In this post, I will share the information I have never fully understood in my previous school life.  In high school, I was taught to do some magic operations with numbers thinking I was doing something cool related to computers. It was fascinating to understand what those numbers represent and why I need to convert the numbers familiar to me, to the ones that consist of only zeros and ones. Getting accepted to the university, I worried I would learn new things without understanding the background of computer science. Luckily, I got a professor who is a master of explaining things other teachers couldn't do. For now, I fully grasp the meaning of the mysterious ones and zeros. Thus, this post aims to explain to you what binary representations are as precise as my teacher did.
 

## What is a binary number system?

Every nationality has its language, which is how people communicate and understand each other. In different countries, the language is different. But what about the people who cannot speak or hear? How do they understand and communicate with others? Another code has been devised for people like that to help in face-to-face communication. It is sign language, in which the hands and arms form movements and gestures that convey individual letters of words or whole words and concepts. For those who can't see, the written word can be replaced with Braille, which uses a system of raised dots that correspond to letters, groups of letters, and whole words.
And after all this information, you can ask how computers are related to this. Thus, we are getting to the point where the binary number system was discovered for every nationality to communicate with computers similarly. We shall see that various types of codes are also used in computers to store and display numbers, sounds, music, pictures, and movies. Computers can't deal with human regulations directly because they can't duplicate how humans use their eyes, ears, mouths, and fingers. The regular number system that we are used to is called decimal which uses ten numbers 0 through 9 to create any number, no matter how large. The binary number system works the same way but only uses two numbers, 0 and 1. For each number in the decimal system, the binary system has its writing which uses only 0 and 1. Computers use binary because it's easy to store ones and zeros as either "on" or "off." Computers can use them to represent more than just numbers: they can represent letters in a Word document (each number corresponds to a character or symbol that is punctuation), colors in a picture, or what you see on your screen.
 

## How to convert decimal numbers into binary and binary into decimal.
 
Now, when you have an understanding of why a computer uses binary numbers, you can learn how to convert decimal numbers into binary.
There are two ways to do this. The first one is the division method. The idea is to divide the number by two until we get a 1 or 0 reminder. To get a binary representation of the number, we collect the reminders from bottom to top.
It is hard to get this by only reading, so here is the [link](https://www.youtube.com/watch?app=desktop&v=UvCZQ5CaWx0) to a perfect video to fully understand this operation in two ways. 

For doing the opposite, as my math professor says you need to have 110% concentration.
Let’s divide the operation into 2 steps.
**Step 1:** List out the powers of 2 for all the digits starting from the rightmost position. The first power would be 2^0 and as we move on it will be 2^1, 2^2, 2^3, 2^4, 2^5, ... In the given example, there are 6 digits, therefore, starting from the rightmost digit, the weight of each position from the right is 2^0,2^1,2^2,2^3,2^4,2^5.

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

**Step 2:** Now multiply each digit in the binary number starting from the right with its respective weight based on its position and evaluate the product. Observe the figure shown below to relate to the step. Finally, sum up all the products obtained for all the digits in the binary number.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oldqj2gpkgdhn2vvjgge.png)
The sum is the decimal number you get.
[Click here for the link to a video: ](https://www.youtube.com/watch?v=4M6L-ubixJo&t=81s)

## How to add and subtract binary numbers.

As we can do some arithmetic operations with the decimal numbers (if you don’t remember decimal numbers are the regular numbers), we can also do that in the binary case. 
 Binary numbers are added following a process similar to the way decimal numbers are added. We need to remember that for binary numbers 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, and 1 + 1 = 10. Just like when adding decimal numbers that equal 10 or more, a 1 is carried over to the left, in binary addition, when the binary addition equals 10 or more, then a 1 is carried over to the left as well.
This is an example of the sum of binary numbers.

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

[Here is the link](https://www.youtube.com/watch?v=jB_sRh5yoZk&t=337s) to a video which will help you to fully understand the addition of the binary numbers.

Another operation we are going to discuss is the subtraction of binary numbers. We need to remember that for binary numbers 0 - 0 = 0, 0 - 1 = 1(Borrow 1 from the next high order digit, 1 - 0 = 1, and 1 - 1 = 0. Here is an example.
  
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bf2jediii26h7hyhhdjw.png)


This is easier than you can think after reading. But watching videos will help you a lot.
Here is the [link](https://www.youtube.com/watch?v=S9LJknZTyos&t=32s)
 
In concluding this post, I want to mention if you have any questions about binary numbers and their operations, you can easily comment, and I will try to answer.
Follow me to learn about binary numbers' multiplication and division also!