How to convert numbers from decimal to binary and back

Decimal Tutorial
By See all their Tutorials
This is a tutorial on how to convert numbers from decimal to binary and from binary to decimal. I may include a really easy hexadecimal shortcut later.

What is binary? In short, binary is a base 2 numbering system used by computer systems. In a given binary digit, the number can be either a 0 or a 1.

What is decimal? In short, decimal is the base 10 numbering system that we use in our everyday lives where digits can range from 0 and 9.

Why should you care? If you are here reading this tutorial then at the very least you are interested in computing. Since binary is so crucial to computing, it is imperative that computer enthusiast/professionals understand how to convert the numbers we use (decimal) to the numbers that computers use (binary).

Lets get started. As previously mentioned, binary digits (or bits) can have a value of either 1 or 0. Well, you might ask, how do you make a number larger than 1 then, if you only have two possible values? The answer is the same way that we make numbers larger than 9 (our largest decimal digit), add another place value.

Understanding place values is the key for any numbering system, with binary no exception. Since you only have 2 possible values, 1 or 0, it is a base 2 numbering system. Then you simply add place values until you reach the number you want. So, the first place value is 2^0. Any number to the 0 power is equal to 1. So that is the 1's place value. The second place value is 2^1. Any number to the 1 power is equal to itself, in this case 2. The third is 2^2 which is equal to 4 and so on.

So to draw it out:

And so on. Or you could write it out like this:

It's the same thing. If you don't want to use exponents, just start with 1 and double it. 1x2 is 2. 2x2 is 4. 4x2 is 8. 8x2 is 16. 16x2 is 32 and so on.

So if you had the number 128 in base 10 and you wanted to convert it to binary, you would simply put a 1 in the 128th place and fill in 0's in all the remaining bit positions so it would be:


Now lets try a harder number. Say 500. Let's draw out the place values to make it clear:

You don't need to go to the 512th's place, since you would not have a group of 512 with only 500.

So first put a 1 in the 256th's place, then subtract 256 from 500 to find your remainder.

500-256 is 244. Look at your next place value, 128. Do you have a group of 128 in 244? Yes, so put a 1 in the 128th's place, subtract it out to find your remainder again.

244-128 is 116. Do you have a group of 64 in 116? Yes, so put your 1 in the 64th's place and subtract it out again.

116-64 is 52. Do you have a group of 32 in 52? Yes. Continue.

52-32 is 20. Do you have a group of 16 in 20? Yes. Continue.

20-16 is 4. Do you have a group of 8 in 4? No, so put a 0 in the 8th's place.

Your next place value is 4. Do you have a group of 4 in 4? Yes, you have 1 so put your 1 there.

Now you have a remainder of 0 and you are done. Simply put 0's in whatever bits you have left.

So 500 in decimal is equal to 111110100. Now you want to check your math so look at your place values and add them back up.

You have a 1 in the 256, 128, 64, 32, 16, and 4's place so add those numbers up and you will get 500. Congratulations, you have done it correctly.

So that was how to convert a decimal number to binary. What if you have a binary number that you want to convert to decimal? It's basically the same thing. Lets take a different number, 110010110101. We want to make that decimal. Simply write out the place values underneath the numbers and add them all up.

OK, so once you know what place values you have, simply add up all the values in which you have a 1 (since a 1 means that you have a group of that number and a 0 means you do not; think of it like this: I have 1 group of 2048, I have 0 groups of 512, etc).

So add 2048+1024+128+32+16+4+1 and you get 3253. Congratulations, you are done. Thank you for reading this tutorial.