# Introduction to Binary

concept

In the digital world we deal exclusively with "on" and "off" as our only two states. This makes a number system with only two numbers a natural choice. In this topic we'll cover the binary number system, what it is and how to convert between it and our usual decimal numbers.

Our usual number system that we use day to day is called the "decimal" system. This comes from the Latin "decimus" meaning "tenth" because each place can have 10 different values.
When you write a decimal number each digit has a "place value". So the number "15" in decimal means:
$$15 = 5\times 1 + 1 \times 10$$
If we created a new number system that only allowed each digit to be a 0 or a 1 we'd have the binary system.
When we write a binary number we often follow it with a subscript of "2" to indicate that it's binary; when we write a decimal number we follow it with a subscript "10" to show that it's decimal.
In the binary case the number "101" would be:
$$101_2 = 1\times 1 + 0\times 2 + 1\times 4$$
Where the "place values" are increasing powers of two rather than powers of ten as in the decimal case.

fact

To convert a binary number to decimal multiply each of the digits by its "place value" (\(2^n\) where \(n\) is the number of digits from the right starting at 0) and sum them.

fact

The first 8 place values (always counting from the rightmost digit) are:

\(2^0\) | 1 |
---|---|

\(2^1\) | 2 |

\(2^2\) | 4 |

\(2^3\) | 8 |

\(2^4\) | 16 |

\(2^5\) | 32 |

\(2^6\) | 64 |

\(2^7\) | 128 |

\(2^8\) | 256 |

You've likely seen these numbers plenty of times when dealing with technology, you'll soon become very familiar with them as you learn to work with digital electronics.
You may have seen the number 255 used frequently with digital things, this is because 255 is the largest number that will fit into an 8 digit binary number (starting at 0). An 8 digit binary number is called a "byte" (with each digit called a "bit"), and it's historically the most common size of a storage unit in a digital system.

example

Convert \(1011_2\) to decimal

The place values (starting from the rightmost digit) are: \(1, 2, 4, 8\) So our number is: $$1011_2 = 1\times 1 + 1\times 2 + 0\times 4 + 1\times 8$$ $$1011_2 = 11_{10}$$example

Convert \(00001011_2\) to decimal

You may notice that reading from right to left this is the same number as in the example above. Adding leading 0s to a binary number has no effect, just like adding leading 0s to a decimal number has no effect. Many times a binary number will be shown with 8 digits (or 16 or 32 or 64) by packing extra 0s on the left. So \(00001011_2 = 11_{10}\). Converting a binary number to decimal is fairly straightforward, we just multiply a 1 or a 0 by its place value and add all the results together.
Converting a decimal number to binary is a little more involved, there are more steps to the process but the process isn't that complicated.

example

Say we have the number \(200_{10}\) and we want to turn it into a binary number, figuring out whether we need a "2" or a "4" is tricky just by looking at it but it turns out that if we always add the largest power of two we can we won't be wrong.
So for instance the largest power of two that is less than 200 is 128. We write down:
\(10000000_2\) as our start for the binary value, now we have to add 1s to make up the remaining \(200-128=72\) left.
Now we do that same again, the largest power of two less than 72 is 64 so we add a 1 at the 64 place:
\(11000000_2\) and we have to make up the other \(72-64 = 8\).
Now 8 is a power of two so we add a 1 to the 8 place:
\(11001000_2 = 200_{10}\) and we're done.

fact

To convert a decimal number to binary start with your binary number \(B = 0\) and your decimal number \(D\) which is given.
Find the largest power of two \(P \leq D\)
Add a 1 to \(B\) in the place for \(P\) and set \(D = D-P\)
Repeat until \(D = 0\).

example

Convert \(216_{10}\) to binary

We start with \(B = 0\) and \(D = 216_{10}\) The largest power of two less than \(D\) is \(P = 128_{10} = 10000000_2\) So \(B = 10000000_2\) and \(D = 216_{10} - 128_{10} = 88_{10}\) Lather, rinse, repeat. \(P = 64_{10} = 1000000_2\) \(B = 11000000_2,\quad D = 88_{10} - 64_{10} = 24_{10}\) \(P = 16_{10} = 10000_2\) \(B = 11010000_2,\quad D = 24_{10}-16_{10} = 8_{10}\) \(P = 8_{10} = 1000_2,\quad D = 8_{10}-8_{10} = 0\) \(B = 11011000_2\) And we're done so: \(216_{10} = 11011000_2\) Now counting in binary takes a little getting used to but you'll get the hang of it. To add 1 we start at the right, if that digit is a 0 we change it to a 1 and we're done.
If that digit is a 1 we change it to a zero and add 1 to the next digit to the left using the same system (if it's 0 make it a 1, if it's a 1 make it 0 and increment the next digit).

fact

The first 8 numbers in binary are:

Decimal | Binary |
---|---|

0 | 0 |

1 | 1 |

2 | 10 |

3 | 11 |

4 | 100 |

5 | 101 |

6 | 110 |

7 | 111 |

fact

Another popular method of converting a decimal number to binary is called the SOAR table.
SOAR stands for:
Step
Operation
Answer
Result
The steps are:

- Divide your decimal number by 2
- Write the integer part of the answer under the "Answer" column
- Write the remaineder part of the answer under the "Remainder" column
- Repeat step 1 with the integer part of your answer until \(A=0\)
- The binary number is the digits in the "Remainder" column read bottom up

example

Find \(29_{10}\) in binary using the SOAR table

We'll set up our table to begin:S | O | A | R |
---|---|---|---|

1 | \(\frac{29}{2}\) | 14 | 1 |

2 | \(\frac{14}{2}\) | 7 | 0 |

3 | \(\frac{7}{2}\) | 3 | 1 |

4 | \(\frac{3}{2}\) | 1 | 1 |

5 | \(\frac{1}{2}\) | 0 | 1 |

practice problems