Binary: Easier than you expected
Tags: binary, beginners, programming, youarenotstupid
Published: 2022-09-15 18:16:08


Throughout history almost every civilization has used a decimal number system with ten digits: 0 through 9. All of the numbers we can possibly think of use some combination of those 10 digits. Computers, however, operate very differently. Instead, they use a number system that has just two digits: **1** and **0**. This system is called **Binary** and your computer uses it all the time. 

Computer needs information in order to do what they do. This digital information or data is made up of something called **Bits**. Bit is short for **B**inary Dig**it**, meaning each bit is really just a single number: either 1 or 0. These bits can be combined to create larger units like bytes, megabytes and so on that we use to measure our files. The larger the file is, the more bits it has.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dsl0w9f040me489m6iik.jpeg)- Why do computers use Binary instead of the decimal numbers? 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/juezrpxncfyqr1ehq194.jpeg)
For now, let's pretend we're stupid and can't count 55+34. If we ask the computer what the answer is, it will probably say 1011001. Now let's convert the Binary to Decimal numbers and get the real sum! 

**1)** Write down the Binary number.
**2)** Write down the powers of 2 starting from 0 from the right to left side. 
**3)** Look at the digits of the Binary number. If the digit above is 0, then we don't count the power of 2 and put 0 instead. If the digit above is 1, we calculate the power and write it down. 
**4)** Count the sum of the numbers we get. The final result is the Decimal representation of the Binary number. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0zlah6zdbgcfryoouqdw.JPEG)
Now let's convert a decimal number into a Binary! The number is 154. We're again working with the powers of 2.

**1)** Take the least power of 2 greater than 154, which is 8 (2^8=256). This means, we need 8 bits to represent the number 154. 
**2)** Write down the powers of 2 starting from 0 to 7 (8 bits) from the right to left side. 
**3)** Pick all the powers of 2, the sum of which will be 154 and put 1 for it. Instead of the rest unused powers put 0. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pmm5c4hwbuh5vb38chux.JPEG) - However, there's another way to convert a Decimal number to Binary.

Divide the number by 2. If there is a remainder, put 1, otherwise, put 0. Division is repeated until we have one remainder at the end. The Binary number will be the one upside down.⇓
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/id3bbs74aqv7vc13wwz4.jpeg)

**Binary Addition** 
To do Binary addition we need to write down the numbers one under another, corresponding the column of the digits from left to right. Then, by following the rules of Binary addition, make the calculations. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9q7h01aw06qvucze1qba.jpeg)

**Binary Multiplication** 

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

References: 
https://www.youtube.com/watch?v=M41M9ATm49M