There’s a joke in computer circles that there are only 10 types of people in the world: those who understand binary, and those who don’t. Hopefully by the end of this article, I’ll make you one of those 10 people who does.
The binary, or base-2, number system isn’t really that hard. It has fewer digits than the base-10, or decimal, system we use normally. With base-2, instead of 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, you only have 0, and 1. You can still represent any number you want though. How does this work? Base-2 seems mysterious because when we use our base-10 numbers, we typically don’t focus on the place value of the digits. “124” is just one hundred twenty-four, but what are you really saying when you say “124”? What you’re actually saying is that you have 1 x 100 + 2 x 10 + 4 x 1
. See the powers of 10 in that equation (1, 10, 100)? That’s why our number system is called base-10. The 1, 10, 100 numbers come from their position in the number. 10^0 = 1, 10^1 = 10 and 10^2 = 100
.
The binary number system works exactly the same way, only we use powers of 2 instead of 10. The equivalent “124” in base-2 would be represented as “1111100” or 1 x 64 + 1 x 32 + 1 x 16 + 1 x 8 + 1 x 4 + 0 x 2 + 0 x 1
. See the powers of 2 in that equation (1, 2, 4, 8, 16, 32, 64)? We get those in the same way we did in the base-10 equation. 2^0 = 1, 2^1 = 2, 2^2 = 4, 2^3 = 8, 2^4 = 16, 2^5 = 32, 2^6 = 64
. You can represent any number you want with base-2. Incidentally, base-2 or base-10, while mostly describing the base number you’re taking the powers of also describes how many digits exist in your number system. Base-2 has two digits (0, 1) and base-10 has ten digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9).
All the same tricks apply in both number systems too. For example, if you take a number and shift off the last digit, what are you really doing? In base-10, you’re dividing by 10. If you took a binary number and shifted off the last digit, you’d have divided the number by 2.
Computers use base-2 for everything they do because of the fact that there are only two possible values in that system, 0 and 1. Computers use electricity and electricity can only be in one of two states: on or off. It can’t be in state 4, or 9. This is why computers can operate at all. Fundamentally, all computers are doing is adding and subtracting numbers (in base-2). From that foundation, you can get to everything else that they do.
Now before I close out this article, I feel obligated to really blow your mind and say that there aren’t just two number systems (binary and decimal). In fact, you can have a number system using any base you want. You could have base-4 or base-3. We commonly use base-8 (octal) and base-16 (hexadecimal). These are used because they can often condense a very long binary number into a shorter value. So our 124 number from earlier had seven digits in binary, but it could be represented with only two in hexadecimal as “7C”. That’s 7 x 16 + C(12) x 1
. Hexadecimal has to use the letters A, B, C, D, E, and F to represent numbers greater than 9 because we don’t have any singular symbol for 12. Remember, “12” is actually 1 x 10 + 2 x 1
.
Well, if that math didn’t scare anyone away, hopefully you now count yourself among the 10 types of people in the world. That’s 1 x 2 + 0 x 1 = 2
.