Number Base Conversion

Decimal to Binary Conversion

Here's another way to convert from decimal into binary. The advantage is that we don't need to calculate powers of two. Some people may find this method easier while others may find it more difficult, so choose whichever technique works best for you.

We can do this by repeatedly dividing the decimal number by 2 and keeping track of the remainder until the decimal number reaches a value of 0.

For example, Let's start with a decimal value of 175.

175 / 2 = 87 with a remainder of 1 This will become the last bit of our result.
87 / 2 = 43 with a remainder of 1
43 / 2 = 21 with a remainder of 1
21 / 2 = 10 with a remainder of 1
10 / 2 = 5 with a remainder of 0
5 / 2 = 2 with a remainder of 1
2 / 2 = 1 with a remainder of 0
1 / 2 = 0 with a remainder of 1 This will become the first bit of our result.

Now we take all of the remainders and collect them, starting with the last one and ending with the first one. The binary value then becomes 1010 1111.

If the result contains fewer bits than we need, we can just add more 0 bits to the left of the result. For instance, if you need a 16 bit number, 1010 1111 becomes 0000 0000 1010 1111 (edited)

Binary to Decimal Conversion

You can also convert from binary to decimal by reversing the method shown above for decimal to binary. Here you start with a value of 0. Then go bit by bit from left to right adding each bit to 2 times the running total until you reach the end of the binary value.

Using the number from the previous example, we will start with the binary value of 1010 1111.

1 + (2 * 0)  = 1 + 0 = 1
0 + (2 * 1)  = 0 + 2 = 2
1 + (2 * 2)  = 1 + 4 = 5
0 + (2 * 5)  = 0 + 10 = 10
1 + (2 * 10)  = 1 + 20 = 21
1 + (2 * 21)  = 1 + 42 = 43
1 + (2 * 43)  = 1 + 86 = 87
1 + (2 * 87)  = 1 + 174 = 175

Our end result is the decimal value of 175. (edited)