Knowledge about binary
Tags: beginners, tutorial
Published: 2022-09-10 22:09:43

In mathematics, the binary number 2 as its base and only needs the two numbers 0 and 1, as like to the typical 10 symbols required by the decimal system. Binary represents the numbers 0 through 10 as 0, 1, 10, 11, 100, 1001, and 1010. The fact of 0 and 1 in electronical gadgets goes like in reali life by terms "on-off," "open-closed," or "go-no go".

The binary numbers here are expressed in the base-2 numeral system. For example, 101 is a binary number. Each digit in this system is said to be a bit.



**_What is Bit in Binary Number?_**

Byte, the basic unit of information in computer storage and. A byte consists of 8 binary digits as known as bits, each of which consists of a 0 or 1. Bytes are the smallest operationable units of storage in computer technology.

10101 is a five-bit binary number
101 is a three-bit binary number
100001 is a six-bit binary number



**Now lets try and convert numbers into binary.**

Example: Convert 4 in binary.

Solution: 

4 in binary is 100

Here, 4 is represented in the decimal number system, where we can represent the number using the digits from 0-9. However, in a binary number system, we use only two digits, such as 0 and 1.

Step 1: First, divide the number 4 by 2. Use the integer quotient  in this step as the dividend for the next step. Continue this step, until the quotient becomes 0. 

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



Step 2: Now, write the remainder in reverse order.(i.e from bottom to top).

Here, the smallest Bit is 0 and the highest Bit is 1.

Hence, the decimal number 4 in binary is 100

So, if we want to find how many bits does 4 in binary have we have to count the number of zeros and ones. 

So, 4 in binary is 100. Here, there are 2 zeroes and 1 one. Hence, we have 3 bits.

Therefore, the number of bits 4 have in binary is 3.


**Convert binary to regular number.**

As we learned in previous topic on how to convert number into binary now we will learn how to the oposite. 
Lets learn the process trought example.

We have the binary 111001 now we want to know what number this represents.

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

From right to left we count from 0 to 5 and write 2 to the power of them times the number as showed in the picture above. Finnaly we add them toghehter and get our answer.




**Binary Arithmetic Operations**

Like we perform the arithmetic operations in normal math, in the same way, we can perform addition, subtraction, multiplication and division operations on Binary numbers. Lets talk about each of them one by one.

**Binary Multiplication**

The multiplication process is the same for the binary numbers as it is for regular numbers. Let us understand it with example.

Example: Multiply 1101 and 1010.

First we multiply the first digit.
Then we add zero to the begining and then multiply the second number by all of them like we did fir the first.
Then we add two zeros and all this steps are the same as forregular multiplication we do in regular math class so nothing unsuall. We continue this step until we get to the last digit and then we add them and get the desired reasult.

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

**Adding in binary **

Now that we know binary numbers, we will learn how to add them. Binary addition is much like your normal everyday addition, except there are some diferrences.
For example: in decimal addition, if you add 8 + 2 you get ten, which you write as 10; in the sum this gives a digit 0 and a carry of 1. Something similar happens in binary addition when you add 1 and 1; the result is two (as always), but since two is written as 10 in binary, we get, after summing 1 + 1 in binary, a digit 0 and a carry of 1.

Therefore in binary:
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 10 (which is 0 carry 1)



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

**Substraction of binary**

 The process of binary subtraction is the same as the arithmetic operation of subtraction that we do with numbers. Since only 0 and 1 are involved here, we may sometimes need to subtract 0 from 1. In this case we have to use the mehod of borrowing as we do in regular mathemathics.
Borrowing is the same when for example: you have to do 8-9 but it is impossible thus you take one from the other high number and give it to 8 and then proceed with the substraction and this concept is the same for binary numbers.


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

Case ii) Binary subtraction with borrowing

Subtract 
101 from 1001. Here number 5 is represented in binary as 
101 and number 9 is represented as 1001.

Step 1: Arrange the numbers as shown below.


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


Step 2: Follow the binary subtraction rules to subtract the numbers. In this subtraction, all the steps are the same as for a regular substraction. The first step is to subtract 1-1. This is equal to 0. Similarly, we move on to the next higher order digit and subtract 0 - 0, which is 0. In the next step, we have to subtract 0 - 1, so we borrow a 1 from the next higher order digit. Therefore, the result of subtracting 0 - 1 is 1.

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

Step 3: Therefore the difference of 
1001 and 101 is 100. To verify this, let us find the decimal equivalent of 100, which is 4, Therefore, 9 - 5 = 4.

**_Dividing in binary_**

Binary division in similar to other arithmetic operations and in this operations binary substraction and also multiplication is used and the other differnece from regular decimal division is that we have to use binary numbers 0 and 1 thus it makesthe binary divison simpler but there arecertain rules that we have to follow.

There are rules we have to follow doing binary division that are similiar to decimal divison.

1. Divison by 0 = meaniningless

2. 0 divided by 0 = 0

3. 1 divided by 1 = 1

There is a method of division called long division and this is the most sufficent way to use whne weare going to do binary division.

If the first digit of the divident is greater than or equal to the divisor then we put 1 in the quotient.
But if it is less that the divisor we put zero in the quotinent.
We reapeat this step until we get to our desired answer.

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








I hope this little information will help you get the base knowladge about binary numbers and how they can be used. How they can be converted to regular number and vice versa and finnaly how can we use them to do arithmetic operations and so on. 



_**References used to write this blog:**_

**_Youtube video:_**https://youtu.be/VLflTjd3lWA
**_Google website:_**https://byjus.com/maths/binary-number-system/#:~:text=Binary%20numbers%20are%20made%20up,is%20a%20single%20binary%20digit.
**_Google website:_**https://www.geeksforgeeks.org/arithmetic-operations-of-binary-numbers/#:~:text=Binary%20arithmetic%20is%20an%20essential,two%20digits%3A%200%20and%201.
**_Youtube video:_**https://youtu.be/LpuPe81bc2w
**_Youtube video:_**https://youtu.be/xHWKYFhhtJQ