One of the few things one can know about computer before getting into it is: it is all just ones and zeros. The meaning of that can only be known once you dive deep in it. Yes, computers run on ones and zeros. It’s definitely a bit more complicated than that, but it’s not so complicated that one can’t understand it!
Those ones and zeros that computers are made up of? Those are based on a type of number system called binary. The binary number system hinges on a simple idea that, instead of counting with 10 digits — the way that we learned to do in kindergarten — you can count with just two digits.
The binary number system that is used in computers today was created by Gottfried Wilhelm Leibniz in 1679. This invention also holds its roots back to the ancient Egyptians.
In our modern day counting system, we have ten possible digits per place. This is why we sometimes hear people refer to our counting system as base 10; another name for it is denary. In the binary number system, we have two possible digits per place, so we can refer to it as counting in base 2. The number of digits possible per place is the only real difference in the way that we count in base 2 versus base 10.
Why Only Binary For Computers?
At the heart of it, computers are made up of switches. What we might not realize is that the switches and circuits that are the building blocks of computers today are effectively the representations of binary.
A computer has billions of (super tiny) digital circuits, which are incredibly simple. They are made up of switches and a switch can only have two states: on or off. Another way to think about this is true or false. In addition, we can represent that on/off binary in yet another way: 1 and 0. To keep it simple let us say, a little bursts of electricity either pass through or do not pass through is based on whether something is switched on or switched off.
When building an electronic device, it is most often desired to have the energy consumption as low as possible and to have a low voltage. Furthermore, electronic signals are not always steady
and can vary because of surrounding influences, like nearby internal circuits for other electronic devices.
Using the 0.5V per step, we assume that electronic circuits could interfere with the voltage levels and make them appear 0.25V higher or lower (this is an arbitrary example).
This might then lead to voltage levels where it gets difficult to distinguish which value it represents. The voltage 0.5 could either mean 1, 2, or 3 since there is the possibility of it falling into the range of 0.25V to 0.75V.
As a result, we cannot divide the 5V into 10 steps. The values could be misinterpreted. A computer might suddenly make wrong calculations because of random interference.
This example of voltage ranges shows that it is necessary to have a safe range between two voltage levels in order to read the correct value with 100 percent probability. This is one of the reasons why the binary system – using only two levels/states – is used in computers. Binary comes from the Latin
language and means that something is composed of two things. Binary electronics are usually called digital electronics.
So there are two staunch reasons for using binary system in computers:
- Two clearly distinct states provide a safety range for reliability.
- Least amount of necessary circuitry, which results in the least amount of space, energy consumption, and cost.
Writing in binary
We know that computers run on binary. And yet none of us type binary into the keyboard! This would lead us to believe that, somehow, what we type into our machines gets converted down to binary. This happens through several layers of abstraction, and we won’t get into all of them.
While it’s not important to know all the layers, I do think that there’s value in knowing a little bit about how that conversion works. We’ll keep it simple and focus on converting between base 10 numbers (integers) to binary.
Transform the decimal number 131 in binary. The method is very simple:
131 divided by 2 gives 65 and the remainder is equal to 1
65 divided by 2 gives 32 and the remainder is equal to 1
32 divided by 2 gives 16 and the remainder is equal to 0
16 divided by 2 gives 8 and the remainder is equal to 0
8 divided by 2 gives 4 and the residue is 0
4 divided by 2 gives 2 and the remainder is equal to 0
2 divided by two gives one and the remainder is equal to 0
1 divided by two gives 0, and the residue is equal to 1
-> We ordered residues, from last to first: 10000011
In binary, write 131 => 10000011
If we do enough binary conversions, we’ll start to notice that even numbers in base ten will always end in 0 when they’re converted into binary. Conversely, odd numbers in base ten will always end in 1 when written in binary.
So this was the miniature calculation of how the computer converts our language which is called high level language to binary. Many other codes such as hexadecimal, ASCII, etc. are also used as an intermediate before being interpreted as binary code.
The power of two
Binary is something that few programmers think about these days. Deep down, we know that it’s important and worth learning about, yet can seem so overwhelming and kind of unnecessary to think about.
But if you think back to when computers used to take up entire rooms (imagine how big the circuits and transistors were back then!) and how far they’ve progressed and how much they’ve changed since then, it’s rather jaw-dropping.
At the very core of that, is binary — language that every computer speaks and understands. So if you’re interested in or work with computers, the basics of binary is worth knowing a little bit about. After all, even though it’s just two numbers, it is, ultimately, what the world around us is written in.
Author – Ashish Patel