The Rolling Coder
The Rolling Coder

What are binary numbers and why do computers use them?


What is a number?

The numbers that we as humans are used to are numbers like 5, 100, 2026. Imagine you are on a game show and are trying to guess the last digit in the price of a car. You have ten possible choices {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. That is why in mathematics the numbers that we are most familiar with are called decimal numbers or base 10 numbers. Base 10 numbers are numbers that consist of digits that can each have 10 potential values {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.

What is the value of a number?

You might think it is silly to ask what is the value of a number. I mean the value of a number is the value of the number, right? Like, the value of 27 is 27! But why do we say that 27 has a smaller value than 72? The answer is because the order of the digits in a number determines its value. This is something that we are all so used to that we don’t give it much thought and probably haven’t given it much thought since about 1st grade. The value of a number is determined by the digits that make up that number and the order of the digits within the number. For base 10 numbers, digits get multiplied by different powers of 10 depending on the digit’s position in the number. Below is an example with the number 256. Notice how in the table below, the exponent of each multiplier is determined by the digit position.

Digit Position 2 1 0
Multiplier (102)=100 (101)=10 (100)=1
Digit 2 5 6

With the table above we can see how we determine the value of a number like 256.

256 = 2 x 102 + 5 x 101 + 6 x 100 = 200 + 50 + 6

What is a binary number?

Binary numbers are just like the decimal or base 10 numbers we are used to. You can count with them, add, subtract, multiply and divide. But unlike base 10 numbers which have 10 potential values for each digit {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} binary numbers only have 2 potential values for each digit {0, 1}. For this reason binary numbers can also be called base 2 numbers because their digits can only have 2 potential values {0, 1}. So, 101 would be a valid binary number but 12 would not because 2 is not a valid digit in a binary number.

What is the value of a binary number?

The value of a binary number is calculated similarly to how the value of a base 10 number is calculated. The difference is that we only have two digits to choose from {0, 1} and since we only have 2 digits to choose from our multipliers will be powers of 2 instead of powers of 10. Below is an example with the binary number 101. Notice how the table below is similar to the table above in that the exponent of each multiplier is determined by the digit position. The table below is different from the table above in that the multipliers are powers of 2 and the digits are only 0s and 1s.

Digit Position 2 1 0
Multiplier (22)=4 (21)=2 (20)=1
Digit 1 0 1

With the table above we can see how we determine the value of a binary number like 101.

101 = 1 x 22 + 0 x 21 + 1 x 20 = 4 + 0 + 1 = 5

If you want to see how changing the digits in a binary number affect its value you can use the interactive table below.

Digit Position 2 1 0
Multiplier (22)=4 (21)=2 (20)=1
Digit

Update the digits in the table above to see how the equation below changes.

101 = 1 x 22 + 0 x 21 + 1 x 20 = 4 + 0 + 1 = 5

Why computers use binary numbers?

You are almost certainly reading this on some type of computer (a smartphone is a computer that can fit in your pocket). Whatever computer you are using probably has some type of calculator app that you can use to do all sorts of calculations using good old decimal numbers that we are used to. But the computer just displays the numbers as decimal because it’s a nice, friendly computer and it knows that decimal is what’s easiest for us humans to understand. Inside the computer, all calculations and logic operations are actually done in binary. So, why is that?

Computers do calculations in binary because data in a computer is stored as electrical values measured as voltages. For a given number, the value of each digit in that number is determined by its voltage in the computer’s memory. If computers used decimal or base 10, then each digit would have 10 different potential values {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. This would mean you would need 10 different voltages to represent the 10 potential values of each digit.

Figure of storing decimal values using 10 different voltages.

The problem with this is that it is difficult and error prone hold a voltage in a narrow range like this. Voltages tend to fluctuate and drift a bit.[1] So, with 10 narrow bins like this the computer may store a 6 in memory but then later when it reads that value from memory the voltage may have drifted into the 5 bin. We can’t have our values changing unexpectedly like this.

But with binary, since there are only 2 potential values for each digit {0, 1} you need only 2 different voltages to represent the 2 potential values of each digit. So, we can have 2 very wide bins. We can even have a gap between the two bins for good measure. And it is much easier and more reliable to hold voltages in 2 wide bins like this. Even if the voltage fluctuates a bit it is highly unlikely that it would drift all the way from the wide 0 bin to the 1 bin or vice versa.

Figure of storing binary values using 2 different voltages.

Today’s computers can do billions of operations per second. With this many operations occurring every second reliability is critical. An error rate of one in a million would mean potentially 1000 errors every second! This is the primary reason why computers use binary instead of decimal. Binary means storing values as voltages in 2 wide bins as opposed to 10 narrow bins. It reduces complexity and increases reliability.

Takeaways

[1] https://www.youtube.com/watch?v=thrx3SBEpL8

License and Trademarks