**Source Learning About Computers**

What are binary numbers? The binary number system is when only two numbers are used – 0 and 1. It is also called base 2. The computer number system is base 2. Our number system is referred to as decimal or base 10 because we use 10 digits (0 – 9) to form all of our numbers. There are many other number bases, including hexadecimal, but it’s easier for computers to utilize 0s and 1s.

In electronics, a 0 is off (usually 0 Volts) and 1 is on (usually 5 Volts). All computer data is composed of 1s and 0s. Each individual 1 or 0 is a bit. Four bits is a nibble. Eight bits is a byte. From there we have kilobytes, megabytes, etc. Since everything is a series of 1s and 0s, the CPU has to perform every calculation in binary. But before any operations are done, numbers have to first be converted into base 2.

But before diving into the binary number system and conversions, let’s first see how things work in our decimal system.

Let’s just pick a number…like 9345. How do we get this? Remember when I mentioned we use base 10? In math the base is a number that’s raised to a power (another name for power is exponent). For example 34 is 3 raised to the 4th power, which means you multiply 3 times itself 4 times (3 * 3 * 3 * 3).

We have what’s called a place value system. Each individual number holds a particular numerical position. We get these positions by using 10 raised to different powers. Start with the number on the right.

So looking at 9345, the right-most number 5 is in the ones place (10º = 1). The 4 is in the tens place (10¹ = 10). The 3 is in the hundreds place (10² = 100), and the 9 is in the thousands place (10³ = 1000). This is true for any number. Now the larger the number the more place values (ten thousands, hundred thousands, etc.), but I’m keeping it short in this example. So we have:

If you take each number, multiply it by its place value, & add the results, you get 9345.

Note: any number raised to 0 = 1. Any number raised to 1 = itself.

This method is used in base 2 except rather than the ones place, tens place, hundreds place, thousands place, etc. you have: ones place (2º), twos place (2¹), fours place (2²), and eights place (2³), etc.

Using the base 10 example just above, the number 1011_{2} is like this:

It’s the same process for any number system. And remember, the computer number system always uses binary. So now that you have a basic understanding of place values, it’s time to start converting!

**Converting From Binary To Decimal:**

Converting binary to decimal is really quite simple. All you do is apply the same technique used in the place value illustration on the intro page except this time we will be using a 2 instead of a 10.

For example if we want to know what 110100011_{2} is in our number system (base 10) we do the following:

We usually start on the right. With each number, you raise 2 to its power then multiply the result by the binary digit. When you’re done, add all the results together and that is the number in base 10.

This method is used for converting any number base to decimal.

**Decimal to Binary Conversion:**

Decimal to binary conversion is not hard either, it just takes a little more work. There are two methods you can use: successive division and subtracting values using a table.

Successive division requires dividing continuously by the base you’re converting to until the quotient equals 0. The remainders compose the answer.

As an example, let’s convert 835 to binary.

The most significant bit is the left number in the answer and the least significant bit is on the right end giving us an answer of: 1101000011_{2}

Binary digits are usually grouped by 4, 8, 16, etc. so we can place a couple of 0s on the left to give us three groups of four. This does not change the answer.

0011 0100 0011_{2}

You can check your answer by converting back to base 10.

We just looked at the successive division method of converting from decimal to binary. The other method is subtracting values. With this method you keep subtracting until you reach 0. Let’s convert 165 to binary.

Notice a 1 is only placed under the highest value that can be subtracted from a number. Everything else is automatically a 0 giving us an answer of: 101001012.

**Hexadecimal:**

The hexadecimal (hex for short) number system uses 16 digits to form all other numbers. The purpose of using hex is for human understanding. Computers always work in binary (0s and 1s). To have a long series of binary digits gets complicated, so programmers had to come up with a more simplfied way to represent them. Hex groups binary numbers into 4 bit packages so to speak. One hex digit represents four bits (called a nibble). Hexadecimal numbers have a subscript 16 or H behind them (D316 or D3H). Because single characters must be used, the letters A, B, C, D, E, F represent 10-15. Remember, when dealing with number systems, we always start with 0. So we have 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. Memory locations are listed as hex values, and many times when you get an error message, your OS (operating system) will show you the location.

Example of hex and the number of bits:

F6AH – 12 bits

BH – 4 bits

78H – 6 bits

**Converting Hexadecimal to Decimal:**

As was mentioned in the binary conversion section above, we use the same technique to convert to decimal (base 10) from any other base. In this case, let’s convert 4B7F16 to Base 10 (decimal).

**Converting Decimal to Hexadecimal:**

To convert from decimal to hexadecimal, we use the successive division method discussed earlier only we divide by 16 instead of 2. Let’s convert 501 from decimal to hex.

We’re done since we can’t divide 1 by 16 and that leaves us with a remainder of 1. When writing the answer the LSD is always on the right and the MSD on the left. The answer is: 1F5_{16}

**Converting Hexadecimal to Binary:**

Remember hex uses groups of four bits, so we can use the table below for conversions.

Decimal |
Binary |
Hex |

0 | 0000 | 0 |

1 | 0001 | 1 |

2 | 0010 | 2 |

3 | 0011 | 3 |

4 | 0100 | 4 |

5 | 0101 | 5 |

6 | 0110 | 6 |

7 | 0111 | 7 |

8 | 1000 | 8 |

9 | 1001 | 9 |

10 | 1010 | A |

11 | 1011 | B |

12 | 1100 | C |

13 | 1101 | D |

14 | 1110 | E |

15 | 1111 | F |

To convert D14B to binary:

D = 1101, 1 = 0001, 4 = 0100, B = 1011

When we put the pieces together, we get: D14B_{16} = 1101000101001011_{2}

**Converting Binary to Hexadecimal:**

To convert 1111010101001110_{2} to base 16, we first break up the number into groups of four as shown below:

1111 0101 0100 1110

Now assign each group its corresponding hex value

1111 = F, 0101 = 5, 0100 = 4, 1110 = 14

When put together, we get F54E_{16}

*Want more information on how to become CompTIA A+ Certified? Learn more!*

*
Also published on Medium. *