Why the Power-of-Two Trick Works for Binary Fractions (And Why It Breaks for Everything Else)

Why the Power-of-Two Trick Works for Binary Fractions (And Why It Breaks for Everything Else)

calendar_today agoschedule3 min read
— Originally published at dev.to

As a 300-level Mechatronics Engineering student studying Digital Electronics, I came across something that changed the way I think about binary conversions — not just as steps to memorize, but as operations with real mathematical meaning underneath them.

Understanding Binary Coded Decimal (BCD) First

Before getting to the trick, it helps to understand Binary Coded Decimal (BCD), specifically the weight codes assigned to binary digits. In a 4-bit system, the weights are 8, 4, 2, 1 (the 8421 code). In a 3-bit system, they are 4, 2, 1 (the 421 code). These codes make binary-to-decimal conversion straightforward.

For example, converting 1111 in base 2 to decimal is simply:

8 + 4 + 2 + 1 = 15

The same logic extends to binary numbers with a fractional part. To convert 1111.0111 from base 2 to decimal, you group the digits in 4-bit sections and apply the weights:

Whole part:      1111 → 8 + 4 + 2 + 1 = 15
Fractional part: 0111 → 0 + 4 + 2 + 1 = 7
Result: 15.7 in decimal

This direction — binary to decimal — is fairly intuitive once you understand BCD weights. The real challenge comes when you go the other way.

The Problem with Decimal to Binary Conversion

Converting a decimal fraction to binary using the standard repeated multiplication method works, but it is long and error-prone. The method requires you to multiply the fractional part by 2 repeatedly, recording the integer part each time and discarding it, until nothing remains. For some numbers this goes on for many steps, and one mistake anywhere gives you a wrong answer.

That frustration is what sparked the idea I want to share here.

The Fraction Shortcut

What if instead of using repeated multiplication, you convert the decimal fraction to a fraction first, then use BCD weight codes to handle the conversion? This connects directly to the concept of fixed-point arithmetic used in embedded systems.

Example 1: Converting 0.25 to Binary

0.25 as a fraction is 1/4. Assuming a 4-bit operation:

  • Numerator: 1 in binary (using 8421 BCD) → 0001
  • Denominator: 4 in binary → 0100

Dividing 0001 by 0100 in binary gives 0.01₂.

Tip: Dividing by a power of 2 in binary is equivalent to shifting the binary point to the left — the same way dividing by 100 in decimal shifts the decimal point two places left.

Using the standard multiplication method on 0.25 gives the same answer: 0.01₂. But the fraction method shows why — it is not magic, it is a point shift.

Example 2: Converting 0.625 to Binary

0.625 as a fraction is 5/8.

  • Numerator: 5 in binary → 101
  • Denominator: 8 in binary → 1000

Dividing 101 by 1000 gives 0.101₂.

Verified with the multiplication method: 0.101₂

Example 3: Converting 0.4375 to Binary

0.4375 as a fraction is 7/16.

  • Numerator: 7 in binary → 0111
  • Denominator: 16 in binary → 10000

Using BCD weights (16, 8, 4, 2, 1), dividing gives 0.0111₂.

Verified with the multiplication method: 0.0111₂

Where This Breaks Down

This shortcut works if and only if the denominator is a power of 2 — that is, 2, 4, 8, 16, 32, and so on.

Try it with 0.2, which as a fraction is 1/5. The denominator is 5, and 5 in binary is 101. Since 101 is not a power of 2, there is no clean point shift. You would have to perform full binary long division, and the result never terminates — it repeats forever as 0.00110011...

Note: This is the same reason 0.1 + 0.2 does not exactly equal 0.3 in most programming languages. The decimal 0.1 is 1/10, and since 10 is not a power of 2, it cannot be represented exactly in binary. This is not a bug — it is a structural limitation of representing base-10 fractions in a base-2 system. Learn more about this in the IEEE 754 floating-point standard.

Conclusion

The power-of-two fraction shortcut offers a clearer, more intuitive path for converting certain decimal fractions to binary. Rather than blindly following the repeated multiplication algorithm, converting the decimal to a fraction and applying BCD weight codes reveals the actual mathematical operation taking place — a simple binary point shift. This works cleanly for denominators that are powers of 2 (such as 2, 4, 8, 16), giving the same result as the standard method while making the reason visible. However, it has a clear limitation: denominators that are not powers of 2 produce non-terminating binary fractions, requiring long division instead. Understanding this boundary does more than just solve conversion problems — it explains one of the most well-known quirks in floating-point arithmetic. The goal of this article was never to introduce a new method, but to show that understanding the structure behind an algorithm is always more powerful than memorizing its steps.

🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

TypeScript Complexity Has Finally Reached the Point of Total Absurdity

Karol Modelskiverified - Apr 23

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelskiverified - Mar 19

MCP Is the USB-C of AI. So Why Are You Plugging Everything In?

Ken W. Algerverified - Jun 10

Your Tech Stack Isn’t Your Ceiling. Your Story Is

Karol Modelskiverified - Apr 9

The Audit Trail of Things: Using Hashgraph as a Digital Caliper for Provenance

Ken W. Algerverified - Apr 28
chevron_left
124 Points3 Badges
Federal University of Technology, Minna, Nigeriadev.to/alfredoeinsteino2024
1Posts
0Comments
Mechatronics Undergraduate | C Programmer | Embedded Systems, IoT & Graphics Developer | Building Real-World Engineering Solutions

Related Jobs

View all jobs →

Commenters (This Week)

2 comments
2 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!