Counting in Binary: As Easy As 0, 1, 10
Numbers versus Numerals
A number is a quantity, and a number does not depend on the numeral system used to represent it — just as your value as a person does not depend on the picture you have on file at your school. Take the number ten for example. Many different numeral symbols have been used to represent the number ten: X (Roman); 10 (Decimal); 1010 (Binary); = (Mayan). Now take the number six for another example: VI (Roman); 6 (Decimal); 110 (Binary); ·| (Mayan). So do you get it? A number is a quantity; a numeral is a symbol or cipher used to represent a number.
Of the four number systems mentioned above — Roman Numerals, Decimal Numerals, Binary Numerals, and Mayan Numerals— the decimal system is superior to our everyday lives for many reasons. For instance, unlike Roman Numerals, Decimal Numerals have a symbol for zero: 0. So if you borrowed some money from your friend and have recently repaid your debt, you can write a note somewhere to remind yourself that you now owe $0! This is pretty cool, when you think about it. For another comparison, Decimal Numerals take less space than Binary Numerals: to write the number seventeen in Decimal form, for example, we only need two digits/bits, a 1 and a 7: 17. To write seventeen in binary form, however, we need five bits/digits, three 0s and two 1s: 10001.
So why do you have to learn binary numerals since decimal numerals is so obviously superior, you ask? My answer to you is simple: because computers count everything in binary numerals, and you want to learn to build computers.
Computers are built with electronic digital integrated circuits. I know this sounds like a mouthful, but don't let the big words impress you just yet. All this means is that computers only care about whether a current or voltage signal is High or Low, which it interprets to mean that some system is either ON or OFF, respectively. The word binary means a system that is based on two different symbols. And since ON and OFF are the only two different states a computer cares to account for, we say the computer speaks in binary. And to make things even easier for us, we use the symbols 0 = OFF = Low and 1 = ON = High to represent the information in a computer.
As fate would have it, using 0s and 1s to represent information on a computer allows engineers who aren't half as smart as Einstein to create computers that can do amazing things! For instance, it is pretty amazing that you are viewing this website on a personal computer while, perhaps, heating your late dinner in your microwave oven thanks to the microchips that allow you to set the timer.
Counting in Binary by Addition
So just how do we count in binary exactly? As a child you probably first learned to discriminate between numbers on your fingers. To convey the number one you showed a finger; then for two you added another finger; then for the number three you added yet another finger; and so on. Let's use the same concept of adding one each time to count in binary. Just keep these two tricks in mind: one plus zero is one; one plus one is two. But in binary addition, for two you write zero and carry the one — just as in decimal for nine plus one you write zero and carry the one. Here we go (use pencil and paper to follow along and continue from where I stop):
Counting in Binary by Position
Another way to count in binary is the exact same way you count in decimal everyday. Step One, start with a single digit and run through each symbol one after the other: like 0,1,2,3,4,5,6,7,8,9. Step Two, when there are no more symbols to run through, just do this: add another digit, increase the symbol on the left by one, and then repeat step one: like 10,11,12,13,14,15,16,17,18,19,20,21,… You get the idea.
Now let's apply the same process to binary numerals: Step One, start with a single bit and run through each symbol one after the other: like 0,1. Step Two, when there are no more symbols to run through, just do this: add another bit, increase the symbol on the left by one, and then repeat step one:
Converting Binary to Decimal
Now I am going to need your help retrieving some stuff from your implicit memory so we can compare binary numerals to decimal numerals. At this point in your life you probably take it for granted that you understand the difference between 2976 and 6792. But if you think back to grade school for a moment you may remember having to learn the difference between units, tens, hundreds, thousands, ten thousands, and so on. And then your teacher probably made you do things like this: 6792 = (6 × 10³) + (7 × 10²) + (9 × 10¹) + (2 × 10º) = (6 × 1000) + (7 × 100) + (9 × 10) + (2 × 1) = 6000 + 700 + 90 + 2 = 6792. Ah… the good old days… Okay now, let's come back to reality. The reason you had to learn this process was so you would understand that the decimal system is weighted by position. Weighted by position means because the decimal system has ten different symbols (0 to 9), each position is a multiple of ten of the rightmost position (A fancy phrase experts and showoffs like to use is positional notation with a radix of ten).
The binary system is a positional system with a radix of two! (Yes, I am an expert.) And what I mean is that each position is a multiple of two of the rightmost position. For examples, let's convert the number six from binary to decimal.
1102 = (1 × 2²) + (1 × 2¹) + (0 × 2º) = (1 × 4) + (1 × 2) + (0 × 1) = 4 + 2 + 0 = 6
Beyond Counting, More Counting
Now that you have learned how to count in binary, let me show you two other operations that you will likely have to perform frequently: conversion of decimal to binary and binary subtraction.
Converting Decimal to Binary
Converting decimal to binary is as easy as dividing by two. Just take the decimal number you wish to convert to binary and divide it by two. Record the remainder. Repeat the process with the result until the result is zero. Let's convert 12 to binary for a demonstration:
Now, write the remainder in reverse; like this: 1100. Voila! 12 = 11002.
In the decimal system, we perform subtraction by adding to a negative number; like this: 9 + (- 4) = 5. Since a computer stores everything in 0s and 1s — hence no room for a negative sign — we must devise a system to distinguish between positive and negative values. Many different systems have been implemented to compute negative binary numbers. The one we will discuss here is called Two's Complement. In the two's complement system, we simply take a binary number, flip every bit (change all 1s to 0s and all 0s to 1s), then add one to the new numeral. Let's demonstrate: 7 = 0111. Hence, to get -7, first we flip every bit to get 1000; then, we add 1 to get 1001. Therefore, -7 = 1001. Notice how I wrote the 7 with a leading zero, 0111. Here is why: a computer that uses the two's complement system starts all positive numbers with a 0 and all negative numbers with a 1; otherwise there would be no way to distinguish between positive and negative numbers.
Now that we know how to represent negative numbers, let's talk about subtracting numbers. You see, computers save information in memory of specific size: 2-bit, 4-bit, 8-bit, 16-bit, 32-bit, etc. Say we have a computer with a 4-bit memory chip. Then to represent the number 2 we must write 0010. So what would -2 look like? Try to do it yourself and see if our answers match:Step one: Flip every bit in 2 to get 1101.
Step two: Add one to the new numeral to get 1110.
Now if indeed 1110 represents -2, we should be able to add 2 to it to get zero. So let's check 2 + (-2) = 0:
Of course we both see the 1 that precedes the four 0s. So how come I say the answer is zero? Remember our computer only has a 4-bit memory? You guessed it! The computer does not see the extra 1 because the four 0s already take up all the space. All the computer sees is 0000!