How to Convert Decimal to Binary

In order to demonstrate how to convert a decimal number to a binary number, we are going to use an example of a decimal number that fits into an 8-bit byte.

Considering an 8-bit byte, the decimal equivalent of each bit is shown as follows:

128 64 32 16 8 4 2 1
x x x x x x x x

Starting with the '128' bit, subtract each of the above decimal numbers from the decimal number that you are trying to convert. For each one, if the result is greater than or equal to 0 then write down a binary 1 and make a note of the result of the subtraction to be used in the next step. If the result is negative, then write down a zero and discard the result, keeping the previous decimal number.

For example, starting with the decimal number 230:

1) Subtract 128 from 230: 230 - 128 = 102. The result is positive, so keep the 102 for the next step and mark a '1' in the '128' position.

128 64 32 16 8 4 2 1
1 x x x x x x x

2) Subtract 64 from 102: 102 - 64 = 38. The result is positive, so keep the 38 for the next step and mark a '1' in the '64' position.

128 64 32 16 8 4 2 1
1 1 x x x x x x

3) Subtract 32 from 38: 38 - 32 = 6. The result is positive, so keep the 6 for the next step and mark a '1' in the '32' position.

128 64 32 16 8 4 2 1
1 1 1 x x x x x

4) Subtract 16 from 6: 6 - 16 = -10. The result is negative, so discard the result, keep the 6 for the next step and mark a '0' in the '16' position.

128 64 32 16 8 4 2 1
1 1 1 0 x x x x

5) Subtract 8 from 6: 6 - 8 = -2. The result is negative, so discard the result, keep the 6 for the next step and mark a '0' in the '8' position.

128 64 32 16 8 4 2 1
1 1 1 0 0 x x x

6) Subtract 4 from 6: 6 - 4 = 2. The result is positive, so keep the 2 for the next step and mark a '1' in the '4' position.

128 64 32 16 8 4 2 1
1 1 1 0 0 1 x x

7) Subtract 2 from 2: 2 - 2 = 0. The result is zero, so keep the 0 for the next step and mark a '1' in the '2' position.

128 64 32 16 8 4 2 1
1 1 1 0 0 1 1 x

8) Subtract 1 from 0: 0 - 1 = -1. The result is negative so mark a '0' in the '8' position. Clearly we don't need to retain the 0 for the next step as there is no next step!

128 64 32 16 8 4 2 1
1 1 1 0 0 1 1 0

So, we now have the binary number 11100110 which is the binary equivalent of 230.

This process works for any decimal and equivalent binary number. However, if the decimal number converts to a binary number with more than 8 bits, we will need to start at step 1 with the most significant bit equivalent to at least the equivalent of the decimal number. For example, if the decimal number were 300, then we need to have the binary bit at least equivalent to 256 in the calculation which will mean a 9-bit binary number. As an example, extrapolating this further, the following figure shows the binary bit equivalents up to 16 bits:

32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1
x x x x x x x x x x x x x x x x