Binary Math – CompTIA Network+ N10-007 – 1.4

You’ll work with binary throughout your career, and you’ll often need to convert between binary and decimal values. In this video, you’ll learn my shortcut for quickly performing binary to decimal conversions.

<< Previous Video: Software-Defined Networking Next: IPv4 Addresses >>

There are only two numbers you need to know when you’re dealing with binary. That’s a 0 and a 1. We call the single digit a bit in the binary system. And if we put eight bits together, we refer to that as a byte. Sometimes you’ll hear this referred to as an octet to designate that there are indeed eight bits for every byte.

In this video, I’m going to show you how to perform some binary math. And they’re very simple calculations, and they usually start with this binary to decimal conversion chart that I have here on the slide. You can see I’ve started at the far right with the number 1, and I’ve doubled that and put a number 2 down. And I doubled that number and put a 4, and doubled that and put an 8, and so on, all the way up to 128. This will be the conversion chart that we use to be able to convert from binary to decimal and back again.

The binary conversion chart we’ve created has eight separate columns. And that’s because those eight columns group together to form a single byte or a single octet. You could, of course, extend these columns so that they’re long enough to perform whatever binary calculation you need. But almost everything we’ll be doing with binary calculations revolves around IP addressing, which means there will be groupings of 8 bits in a single byte.

Let’s use this conversion chart to convert from a binary value to a decimal value. And we’ll take this binary value, 0 0 0 0 0 0 1 0. And we’ll convert that to decimal. The first thing we’ll do is write out all of those individual bits in order. And of course, we’re trying to find what the decimal value of that might be. Just above these bits, we’re going to write our conversion chart.

So we start with 1, double it to 2, to 4, 8, all the way to 128. So now you can see there is a separate value listed along with each individual bit that we’re trying to convert. What we’ll do is add all of these values based on the numbers in our conversion chart. Every place there is is 0, we’re going to bring down a 0. But every place there is a 1, we’re going to bring down the value that’s associated with that place in our conversion chart.

So we see just above this 1 is the number 2. So we will bring down a 2. And if we put all of these together, add them all up, we will get a value of 2 decimal, which means 0 0 0 0 0 0 1 0 is 2 in decimal.

Let’s perform another conversion of binary to decimal. It’ll be exactly the same process again, although this binary number is 1 0 0 0 0 0 1 0. So we’ll write down our entire binary value. We’ll put our conversion chart numbers at the top.

Now let’s bring down these values. Every place there’s a 1, we’re going to bring down the value from our conversion chart. And in every place there’s a 0, we’re going to simply bring down a 0. And if we add up the 128 plus 2, we get 130 decimal, which is the conversion of the binary value 1 0 0 0 0 0 1 0.

Let’s do one more. We’ve got binary 1 1 11 1 1 1 1. So we’re bringing all 1s down and putting all of our conversion chart numbers at the top. This means that we’re going to pull down every single 1 of those conversion chart numbers, add them all together to come up with 255 in decimal.

Now let’s reverse the process. Let’s start with a decimal value, and let’s determine what the binary equivalent is of that decimal value. And we’ll start with decimal 154, and we’ll determine what the binary representation of that might be.

Normally, we would list out the binary numbers. But obviously, we don’t know what those are yet. But we will put our conversion chart right on the top of these unknown values. There is only one combination of 0s and 1s that would equal 154 in binary. So what we’ll do is step through each one of those decisions to see if we put a 1 or 0 in each one of those columns.

We’ll start with the 128 that happens to be on the far left, and we’ll ask, is 128 less than or equal to the 154 decimal that we’re trying to find. And in this case, 128 is less than or equal to 154, quite a bit less. So we’ll put a 1 in that particular place, and we’ll bring down the 128.

Now let’s look at the next value, which is a 64. So if we add 128 and 64, which happens to be 192, is that less than or equal to 154? In this case, no. It’s more than 154. So we would put a 0 in that particular column.

Let’s perform the same question with the next column over, which is the 32. Is 128 plus 32– happens to be 160– less than or equal to 154? That is not less than or equal to 154 so we put a zero.

The next values a 16. Is 128 plus 16, which is 144, less than or equal to 154? And it is less than or equal to that value. So we’ll put a 16. So now, 144 is the number that we have so far, 128 plus 16.

So is 144 plus 8, our next column, less than or equal to 154? It is. 152 is less than or equal to 154. So we’ll bring down the value of 8. We’ll ask the same question of the next column, which is a 4. Is 152 plus 4 less than or equal to 154? It’s not. It’s more than 154. We’ll ask the same question in the 2 column. Is 152 plus 2, which is 154, less than or equal to 154? And it is equal to 154.

And now that we finally reached that value, all of the remaining bits will happen to be 0. There’s only one column left, so we’ll put a 0 in that column. So if we check our math, 128 plus 16 plus 8 plus 2 is 154, which means that 1 0 0 1 1 0 1 0 is the binary representation of 154 decimal.

If there are a fewer number of bits available for a calculation, then that means there are a fewer number of decimal representations of that value. For example, if there are two bits available, the only possible options are 0, 1, 2, and 3. If there’s three bits available, you’ve got 0 through 7. If four bits are available, you’ve got 0 through 15, and so on. So depending on how many binary bits will be available will determine what the range will be for the decimal equivalent.

When we were writing out our conversion chart, we were really writing out the powers of 2. For example, 2 to the 0 power is 1. 2 to the first power is 2, to the second power is 4, and so on.

And a number of the calculations that we’ll convert to and from binary will use this particular chart. You’ll use it for subnetting other types of binary calculations. And it will be a task that you become very familiar with as you go through your networking career.