Math for Programmers — Considerations From Decimal to Binary

Original article was published by Christopher Tao on Artificial Intelligence on Medium

Math for Programmers — Considerations From Decimal to Binary

Why computers use the binary number system?

It is well known that binary numbers are the basis of the classic computer world that is built by John von Neumann. Yes, when I say the classic computer, it is the device you’re using at the moment unless you’re working as a researcher in the quantum computing area.

What are the considerations between the two different number systems? And why binary is used but not decimal? It is not difficult but important as the basic knowledge of computer science. In this article, I’ll share some considerations about decimal and binary number systems.

The Decimal Number System

Photo by geralt on Pixabay

I still remember when I was a kid, the teacher starts to teach us some numbers larger than 10. When she mentioned 11, I wrote down “101” on my paper and thought that would be correct. Unlike “ten” and “one” that is different from “eleven” in English, in my mother tongue, the pronunciation of 10 followed by the pronunciation of 1 is exactly how to say 11.

After that lesson, I realised that the digit at a certain place has its own meanings strictly 🙂 However, if we’re using the Roman Numbers, writing the ten “X” followed by one “I” is exactly 11 -> “XI”.

Of course, the place of the digits plays an important role in Arabic Numbers. In the decimal number system, we have 10 different numbers that are 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.

Consider the number 3105 shown above, it can be written into the form as follows.

You must have already found the patterns:

  • The base of all the exponents is 10 because the number is a decimal number.
  • The exponents from right to left are 0, 1, 2, 3 because there are 4 digits in this decimal number. They are ones place, tens place, hundreds place and thousands place.

Therefore, we can use the exponents of 10 to re-write every decimal number, and they must follow the patterns as above shown.

Then, how about the binary number system?

The Binary Number System

Photo by GDJ on Pixabay

Do you still remember we have 10 different digits in the decimal number system? In the binary number system, we have only two numbers: 0 and 1.

Similarly, we can also re-write a binary number using the same technique, following a similar pattern, but not exactly.

  • The base of all the exponents is 2 because the number is a binary number.
  • The exponents from right to left are 0, 1, 2, 3 because there are 4 digits in this decimal number. They are ones place, twos place, fours place and eights place.

The differences in the binary number are shown above in the bold text.

By knowing such, we can convert a binary number into decimal using the pattern we have found. For example, we want to convert the 3105 from a decimal number to binary. We can firstly prepare a list of exponents of 2 as follows.

Then, we can select the maximum number that is smaller than closest to the number we want to convert. 4096 is larger than 3105, so we have to select 2¹¹ which is 2048.

Then, we use 3105 minus 2048 and has 1057 left. After that, the 2¹⁰, which is 1024 is the next closest one to be selected, so we have 1057 minus 1024 equals 33. The exponents closest to 33 is 2⁵ which is 32, and then we have only 1 left which is 2⁰.

So, we have selected 2¹¹, 2¹⁰, 2⁵ and 2⁰. Recall that the exponents 11, 10, 5 and 0 mean the places, so we just need to right 1 on these places and 0 for the other places.

The binary number of 3105 is 110000100001.

There is an easy way if you don’t want to prepare a list of exponents or the number is too large. The method below can decide 1 digital by each time you divide the number by 2.

Every time we divide the number by 2, the reminder has to be either 0 or 1. The reverse of the reminders will be the binary number converted from the decimal number.

Why Computer Uses the Binary Number?

Photo by blickpixel on Pixabay

To understand why the binary number system is used in the computer systems but not decimal, we need to start from the number of types of the digits we need.

As above-mentioned, the decimal number system needs 10 different digits to express a number. In other words, there are 10 different possibilities for each place. However, in the binary number system, we just need 2.

Suppose that you got a switch, it is very easy to have two different statuses: On and Off. Yes, that’s how we express 1 and 0 in the computer world. Is that possible to design such a switch can have 10 different statuses? Well, I’m not an electronic engineer. I would say it might be possible but the complexity gonna be much higher.

Let’s use addition operation as an example because it is the basis of others such as multiplication. In the binary system, the addition table is as follows.

However, if insist to use the decimal number system, we have to let the CPU to understand the addition table as follows.

Are there any drawbacks for the binary number system? Of course, think about the number 3105 we’ve just converted into a binary number, which is 110000100001. Suppose you and me, all of us can read binary numbers, we need to write 12 digits to express such a number. When you want to tell me the number three thousand one hundred and five, you have to say one one zero zero zero zero one zero zero zero zero one. I don’t think I can follow…

Therefore, the drawback of a binary number is that it has to use too many digits to express a number that is not that large.

However, this drawback is not for computer. No matter how many digits we have, they will just be stored in the CPU cache. So, computers do not care how many digits there are. On the contrary, they are not good at dealing with too many rules, such as the addition tables above-shown. Therefore, the binary system becomes a perfect option for computers.


Photo by Skitterphoto on Pixabay

In this article, I have explained the different number systems in my understanding, decimal and binary. Our human use decimal because it has more types of digits, but we don’t have to use too many digits to express a number. Also, we all have 10 fingers which are intuitively used for counting. In other words, decimal has an almost perfect balance between the number of digits and the number of types of digits. Computers use the binary system because they do not need such a balance. Instead, they need as fewer number of rules as possible, and they do not care about the number of digits. Therefore, binary is on the extreme side of “fewer rules” and become the perfect choice for computers.