DEV Community

Cover image for What is "Binary" and how are they understood by the computer?
svetlanatad
svetlanatad

Posted on

What is "Binary" and how are they understood by the computer?

What are binary numbers?
Binary numbers, roughly said, are the language between computers. Us humans use so many languages to understand each other, while computers only need 1s and 0s to communicate between each other. Basically, copmuters are a powerful combination of electrical circuits. Therefore, there are only two behaviours for the electricity: it either is on (which is the 1 state) or off (0). Hardware engineers deal with the hard work of creating a platform for us, software engineers, to work in with the binary numbers in this case, since this blog post is all about understanding what the binary numbers are and how to work with them.
Now, we have a platform to understand the binary numbers (i.e. basically the computer). Apparently, all numbers can be represented by a power of 2: Let's say, 39 = 2^(5) + 2^(2) + 2^(1) + 2^(0). Now, we want the computer to understand the number 39 with 1s and 0s, right? Since the largest power of 2 we have is 5, and since we are gonna start counting from 0, we need 6 "places" to represent the number 39. Those "places" are called bits. Anyway, 39 = 1*2^(5) + 0*2^(4) + 0*2^(3) + 1*2^(2) + 1*2^(1) + 1*2^(0). Correct, right? Now let's pay attention to the coefficients in front of the 2s, those are all 1s and 0s. Therefore, it is logical to conclude that the "1-0" representation of 39 is the easiest combination of those coefficients, which is, 100111.
It turns out, that 100111 is indeed the binary representation, and the binary number for the number 39 in the base 10 representation. (Base 10 representation is the numbers we are mostly famililar with and work with them at school). Now let's try converting the binary number 100111 back to decimal one. We are counting from 0, so since we have 6 digits of the binary number, the largest power of 2 we have is 5. We are going to do the same thing we did in backwards. 10111 = 1*2^(5) + 0*2^(4) + 0*2^(3) + 1*2^(2) + 1*2^(1) + 1*2^(0), which is indeed 39. Did you know that 39 is read as "Sankyu" in Japanese which sounds like Thank you?

Now, back to the topic, how do we add those binary numbers together? Very simple: since there are only three ways to add binary numbers together, which are...
i) 0+0=0
ii)1+0=0+1=1
iii)1+1=... oops? what do we do? Well, in decimal 10 base system 1 plus 1 is equal to 2 right? So, we know how to represent 2 in binary already, because 2 = 1*2^(1)+0*2^(0) so 2 is 10. Therefore, 1 + 1 = 10.

Knowing this, believe me, you can add any binary numbers together. If you don't believe me, try for yourself. Here is an example for the decoration:
1011+1111=11010
(10base: 11 + 15 = 26)

The multiplication is even more simple. Basing that we already know how to add binary numbers together, there are two remaining rules for multiplication:

i)0*0=0*1=1*0=0
ii)1*1=1

Now let's try multiplying binary numbers together:

1011
Enter fullscreen mode Exit fullscreen mode

x1111
----
1011

  • 1011 1011 1011 --------- =10100101

Indeed, you may check the correctness of this by converting the numbers back to decimal and the other way around again. It's a good practice, isn't it?

The main point in understanding what binary numbers was that, it's a work with the number 2 and counting from 0, because, everything else follows from that. Now, I hope, it is more clear for the reader what binary numbers are and how the computer understands them. Thank you for reading my post, my dear instructor <3

Top comments (0)