Tutorials

HOW BINARY NUMBERS WORK

by Carrie Sundra
Learn binary with these re-writable stitch markers!


A while ago I released BitMarkers - binary stitch markers for knitters and crocheters. I didn't worry too much about a supporting how-to or blog page, because there are a lot of binary number tutorials on the interwebs. But after seeing that the most popular ones tend to dive straight into exponential notation and math-heavy explanations, I decided to go ahead and write my own. This is intended for beginners, and focuses on re-learning how numbering systems work in hopefully a more intuitive way. Then it goes into exponents at the very end.

$
19.95
 
$
To put everything in context, let's first review a "normal" number.
Each digit in our number can be 0 through 9. So including 0, there are 10 possible choices for each digit. This is called a base 10 numbering system, and is colloquially known as "decimal". It's also called the "Hindu-Arabic numeral system" after its origins.


​In binary, there are only 2 possible choices for each digit: 0 or 1. So it's known as a base 2 numbering system, or binary.
Why only 2 choices? It all boils down to how computers work, electricity, and voltage. Computers can sense the presence of a voltage, or the absence of a voltage. It's either there or it's not. Presence/There = 1, Absence/Not There = 0. So if that's the medium you have for storing and reading information - basically either something's there and it's a 1, or something's not there and it's a 0 - you have to develop a language where you can communicate concepts based on long strings of 1's and 0's. This language is binary.

Binary Counting Method 1 - Rolling over Bits

I think the simplest way to think about counting in binary is to compare it to counting in decimal. What happens when we go from the number 9 to the number 10? Our "9" digit resets to 0, and the next digit rolls over to 1.
The same thing happens with binary. But since we only have 2 numbers possible with each digit, the rollover happens much sooner, at the number 2.
...and the digits just keep counting up and resetting and rolling over:
Each binary digit is called a "bit". 8 bits are called a byte. So if you have 128 GB of memory on your phone, you can store 128,000,000,000 bytes. That's 1,024,000,000,000 bits!

Binary Counting Method 2 - The Places

Another way to think about numbers is by their places. In a 3-digit decimal number, we have the ones, tens, and hundreds places:
We're so used to counting in decimal that we just know 198 = 198. But if we were explaining it to an alien, we could break it down like this:


1. There's an 8 in the ones place, and 8 x 1 = 8.
2. There's a 9 in the tens place, and 9 x 10 = 90.
3. There's a 1 in the hundreds place, and 1 x 100 = 100.
4. Add them all up: 8 + 90 + 100 = 198


Easy-peasy! So let's now do the same thing with a binary number:
Whoa! Only having 2 numbers per digit makes each digit rollover sooner and it looks confusing because we don't natively speak binary. But look up at the previous section - remember how 100 = 4? Does it start to make sense that the third digit would be the fours place? Let's break this number down!


​1. ones place: 1 x 1 = 1
2. twos place: 0 x 2 = 0
3. fours place: 1 x 4 = 4
4. eights place: 0 x 8 = 0
5. 16s place: 1 x 16 = 16
6. 32s place: 1 x 32 = 32
7. Add them all up: 1 + 0 + 4 + 0 + 16 + 32 = 53


Congratulations! You now know a super long way to write the number 53.

Binary Counting Method 3 - Exponents

This is what most tutorials teach because it's technically the "truest" way of converting between numbering systems. But it's also the most mathy, and if you're not a mathy person, it can be confusing to start with this explanation. However, you've already read the above two methods, so you're totes ready for exponents.


Most of us are reasonably familiar with an exponent of 2, so we'll start there. If a number has an exponent of 2, it means the number is "squared" or that you multiple the number by itself.
Another way of thinking about an exponent of 2, is that it means 2 of the number are multiplied together.
An exponent of 3 means 3 of the number are multiplied together.
If you keep adding one to the exponent, you keep adding another multiplication by 3.
3^4 = 3 x 3 x 3 x 3 = 81
3^5 = 3 x 3 x 3 x 3 x 3 = 243
(The symbol "^" is also called "carrot" which means "to the" or indicates an exponent).


​But what happens if the exponent is 1? Or 0?
It's a little weird, but just think of it this way.
  • Any number to the exponent of 1 is just itself. 3^1 = 3. 52^1 = 52.
  • Any number to the exponent of 0 is 1. Always. 3^0 = 1. 524^0 = 1. 1^0 = 1.

Now we're ready to explain to our alien visitor how decimal numbers work using exponents, because each digit's place can also be thought of in terms of exponents.

We can go through the same exercise of calculating the value of each digit, using exponential representation.


1. 8 x 10^0 = 8 x 1 = 8
2. 9 x 10^1 = 9 x 10 = 90
3. 1 x 10^2 = 1 x 100 = 100
4. Add them all up: 8 + 90 + 100 = 198


Ready for the same thing with our binary number?
Ok, same steps:


1. 1 x 2^0 = 1 x 1 = 1
2. 0 x 2^1 = 0 x 2 = 0
3. 1 x 2^2 = 1 x 4 = 4
4. 0 x 2^3 = 0 x 8 = 0
5. 1 x 2^4 = 1 x 16 = 16
6. 1 x 2^5 = 1 x 32 = 32
7. Add them all up: 1 + 0 + 4 + 0 + 16 + 32 = 53


There you go! You're now ready to decode any binary number.