The intuition behind decimal-to-binary conversion

A quick search for conversion methods turns up four standard techniques: two for whole numbers and two for fractional values. While knowing these methods is usually sufficient, understanding why they work can be a powerful memory aid. The second half of this article walks through the underlying arithmetic. Grabbing a pen and paper and working through the steps alongside the text is highly recommended for retention.

The four algorithms, along with worked examples, are presented below.

Whole number conversion

To convert a whole number to binary, repeatedly divide it by 2, recording both the quotient and the remainder at each stage. Keep dividing the new quotient by 2 until it reaches zero. After that, read the remainders in reverse order to get the binary representation.

Consider converting the number 12 as an example. Dividing by 2 and tracking the quotient and remainder yields:

The simple math behind decimal-binary conversion algorithms — figure 1

Listing the remainders from last to first gives 1100. Therefore, the decimal 12 is written as 1100 in binary.

Fractional value conversion

For fractions, the process involves multiplying the fractional part by 2 and noting the resulting integer and fractional components. Repeat this multiplication until the fractional part becomes zero. The sequence of integer parts obtained forms the binary representation.

Let’s apply this to the fraction 0.375:

The simple math behind decimal-binary conversion algorithms — figure 2

The integer parts generated at each step are 0.011. Hence, the decimal 0.375 is represented as 0.011 in binary.

Only fractions whose denominator is a power of two have a finite binary representation. Since the denominators of 0.1 (1/10) and 0.2 (1/5) are not powers of two, these numbers cannot be stored exactly in binary. They are rounded to the available mantissa bits when stored as IEEE-754 floating-point numbers — 10 bits for half-precision, 23 bits for single-precision, or 52 bits for double-precision. Depending on the precision used, the floating-point approximations of 0.1 and 0.2 may be slightly above or below their decimal counterparts, but they are never exact. Due to this, 0.1 + 0.2 will never equal 0.3.

Converting a binary whole number back to decimal

Working from the leftmost digit, take your running total, multiply it by 2, and then add the current bit. Repeat this process until every bit has been processed.

Using the binary number 1011 as an example:

The simple math behind decimal-binary conversion algorithms — figure 3

Converting a binary fraction back to decimal

To decode a binary fraction, start with the rightmost bit and a total of 0. For each digit, add it to the current total and then divide the sum by 2. Continue until no digits remain. The binary fraction 0.1011 is used here as an example, with division by 2 shown as multiplication by 1/2.

The simple math behind decimal-binary conversion algorithms — figure 4

Those are the four fundamental algorithms for moving between binary and decimal systems.

Expressing numbers as base‑q expansions

To understand why these methods work, we need to look at the base-q expansion of a number. Any integer can be expressed as:

The simple math behind decimal-binary conversion algorithms — figure 5

where,

  • N is the integer
  • x is a single digit (0–9 for base-10, 0–1 for base-2)
  • q is the base (10 for decimal, 2 for binary)

This form will be called the base q expansion for short. As an illustration, the number 12 can be written in both decimal and binary as:

The simple math behind decimal-binary conversion algorithms — figure 6

Fractions can also be expressed in a similar way:

The simple math behind decimal-binary conversion algorithms — figure 7

where,

  • N is the fractional part
  • x is a single digit (0–9 for base-10, 0–1 for base-2)
  • q is the base (10 for decimal, 2 for binary)

For 0.375, the representations in decimal and binary are:

The simple math behind decimal-binary conversion algorithms — figure 8

Whole number conversion explained

The base-q expansion provides a way to see exactly what the division algorithm does. Let’s rework the conversion of 12, but as if the binary digits were unknown. We start with an expansion containing placeholder x symbols:

The simple math behind decimal-binary conversion algorithms — figure 9

The goal is now to find each x. A key observation is that every term except the last is divisible by 2, so they are all even. This means the digit x0 is determined by whether the original number is even (x0 = 0) or odd (x0 = 1). Since 12 is even, we get:

The simple math behind decimal-binary conversion algorithms — figure 10

To find x1, we notice that all terms from x1 up to xN are multiples of 2. Factoring out 2 isolates something useful:

The simple math behind decimal-binary conversion algorithms — figure 11

Since the value inside the parentheses is 6, our first step can be written as:

The simple math behind decimal-binary conversion algorithms — figure 12

Repeating this logic, we treat the polynomial inside the parentheses as a new equation:

The simple math behind decimal-binary conversion algorithms — figure 13

The same reasoning tells us x1 is 0. We can write that down and factor out 2 once more:

The simple math behind decimal-binary conversion algorithms — figure 14

Our second step becomes:

The simple math behind decimal-binary conversion algorithms — figure 15

At this point the pattern is clear. We keep factoring out 2 until the quotient reaches zero. Continuing with this approach:

The simple math behind decimal-binary conversion algorithms — figure 16

With only one summand remaining and a quotient of 1, we reshuffle the expression:

The simple math behind decimal-binary conversion algorithms — figure 17

This is the third step:

The simple math behind decimal-binary conversion algorithms — figure 18

The result now reads:

The simple math behind decimal-binary conversion algorithms — figure 19

Obviously x3 is 1. To fit our algorithm’s format, though, we rewrite it with an explicit quotient:

The simple math behind decimal-binary conversion algorithms — figure 20

Since the quotient is now 0, nothing remains to be processed. This is the final step:

The simple math behind decimal-binary conversion algorithms — figure 21

That completes the conversion. Reviewing the complete set of steps:

The simple math behind decimal-binary conversion algorithms — figure 22

Each remainder lines up with one of the x placeholders: the first remainder for the first digit, the second for the next, and so on. Consequently, 12 in binary is 1100 under this method.

Recall that this derivation started from the question of why dividing by 2 works. If we move the factor of 2 to the left side of each equation, we get:

The simple math behind decimal-binary conversion algorithms — figure 23

This makes it clear how the division algorithm emerges from the math. A more compact way to show all four steps together is:

The simple math behind decimal-binary conversion algorithms — figure 24

It is worth ensuring you understand this representational shortcut, since it will be important when dissecting the reverse conversion.

Fractional conversion explained

The reason multiplication by 2 works for fractions is also found in the base-q expansion form. Getting back to our earlier example of 0.375, we again pretend the binary bits are unknown:

The simple math behind decimal-binary conversion algorithms — figure 25

The aim is still to solve for each x. Noticing that negative powers of 2 produce fractions with denominators that are positive powers of 2, we rewrite the expansion:

The simple math behind decimal-binary conversion algorithms — figure 26

Factor out 1/2 from the right-hand side of the expression:

The simple math behind decimal-binary conversion algorithms — figure 27

Then move it to the other side:

The simple math behind decimal-binary conversion algorithms — figure 28

At this point x1 is isolated, and it must be either 0 or 1. To decide, examine the remaining terms inside the parentheses:

The simple math behind decimal-binary conversion algorithms — figure 29

Considering the maximum possible value of this sum, if we set every x to 1, we get:

The simple math behind decimal-binary conversion algorithms — figure 30

This is a geometric series whose total falls within the range [0 < sum < 1]. It cannot reach 1. The relevant part of our current equation is:

The simple math behind decimal-binary conversion algorithms — figure 31

Since the quantity on the right is strictly less than 1, it forces x1 to be 0 rather than 1. The remaining portion is then 0.75.

The simple math behind decimal-binary conversion algorithms — figure 32

This corresponds exactly to the initial move in the algorithm:

The simple math behind decimal-binary conversion algorithms — figure 33

Next, we take the fractional part, 0.75, and factor out another 1/2 to expose x2:

The simple math behind decimal-binary conversion algorithms — figure 34

Move the 1/2 to the other side of the equation:

The simple math behind decimal-binary conversion algorithms — figure 35

Here, if x2 is 0, the sum on the left could never reach 1.5, which is the value we have. Thus x2 must be 1, leaving 0.5 remaining.

The simple math behind decimal-binary conversion algorithms — figure 36

This follows the same rhythm as the original algorithm:

The simple math behind decimal-binary conversion algorithms — figure 37

Repeating the procedure with the leftover 0.5:

The simple math behind decimal-binary conversion algorithms — figure 38

The same reasoning shows x3 is 1, and the fractional part is gone:

The simple math behind decimal-binary conversion algorithms — figure 39

With no fractional remainder, this is the last step:

The simple math behind decimal-binary conversion algorithms — figure 40

Collect all the steps together:

The simple math behind decimal-binary conversion algorithms — figure 41

That is precisely the algorithm from the beginning of this discussion. Like with whole numbers, we can condense the three stages into one representation:

The simple math behind decimal-binary conversion algorithms — figure 42

Make sure you are comfortable with this condensed version, because it will be a key tool in understanding how binary-to-decimal conversion works.

What prevents certain fractions from having a finite binary representation

Developers are often caught off guard by the fact that a fraction like 0.1, which terminates cleanly in decimal, never terminates in binary. This quirk sits at the very heart of the well-known floating-point surprise when 0.1 + 0.2 does not equal 0.3. The core question is: what makes a fraction representable with a finite number of digits in a given base? The full answer is nuanced. But the simplified rule is this — a fraction has a finite representation only when its denominator is a power of the base. In base 10, the denominator must be a power of 10. That’s why 0.625 has a tidy decimal form:

The simple math behind decimal-binary conversion algorithms — figure 43

while 1/3 stretches out endlessly:

The simple math behind decimal-binary conversion algorithms — figure 44

The identical logic governs base 2:

The simple math behind decimal-binary conversion algorithms — figure 45

Now consider 0.1. Its denominator is 10, which is not a power of 2, so 0.1 becomes an endless fraction once translated into binary. Running it through the algorithm from earlier makes this visible:

The simple math behind decimal-binary conversion algorithms — figure 46

The pattern repeats forever, so we can capture it as a periodic continued fraction:

The simple math behind decimal-binary conversion algorithms — figure 47

Turning a binary integer into a decimal one

To demonstrate why the doubling method works, I’ll reuse the binary integer 1011 from the opening section. Once again, we lean on the base-q expansion form of the number. Here it is written out:

The simple math behind decimal-binary conversion algorithms — figure 48

Since every term in the sum contains a factor of 2, we can repeatedly pull out 2 until the quotient drops to zero. Here’s that process:

The simple math behind decimal-binary conversion algorithms — figure 49

If you now evaluate the expression following standard arithmetic precedence, you’ll arrive at precisely the steps shown in the earlier section:

The simple math behind decimal-binary conversion algorithms — figure 50
The simple math behind decimal-binary conversion algorithms — figure 51

So the binary value 1011 equals 11 in decimal.

Turning a binary fraction into a decimal one

We’ve reached the final algorithm. You may have already deduced how it works on your own. If not, here’s the reasoning. The base-q expansion form again holds the key. Let’s take 0.1011 from the first section and write it in expanded form:

The simple math behind decimal-binary conversion algorithms — figure 52

Because every term carries a factor of 1/2, we can factor out 1/2 repeatedly until no fractional component remains. The procedure looks like this:

The simple math behind decimal-binary conversion algorithms — figure 53

Respecting the order of operations yields the algorithm described at the start:

The simple math behind decimal-binary conversion algorithms — figure 54
The simple math behind decimal-binary conversion algorithms — figure 55

Hence, 0.1011 in binary translates to 0.6875 in decimal.