<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Toluwanimi Alfred</title>
    <description>The latest articles on DEV Community by Toluwanimi Alfred (@alfredoeinsteino2024).</description>
    <link>https://dev.to/alfredoeinsteino2024</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3990902%2Fbd4fe494-8036-4ad6-adeb-868c89da5300.jpg</url>
      <title>DEV Community: Toluwanimi Alfred</title>
      <link>https://dev.to/alfredoeinsteino2024</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alfredoeinsteino2024"/>
    <language>en</language>
    <item>
      <title>Building a Serverless Agriculture Platform with AWS</title>
      <dc:creator>Toluwanimi Alfred</dc:creator>
      <pubDate>Wed, 02 Sep 2026 03:21:05 +0000</pubDate>
      <link>https://dev.to/alfredoeinsteino2024/building-a-serverless-agriculture-platform-with-aws-2ao3</link>
      <guid>https://dev.to/alfredoeinsteino2024/building-a-serverless-agriculture-platform-with-aws-2ao3</guid>
      <description>&lt;p&gt;While building &lt;strong&gt;HarvestIQ&lt;/strong&gt;, I started paying much more attention to how backend architecture affects the way a product can be built, deployed, and scaled.&lt;/p&gt;

&lt;p&gt;HarvestIQ is an agriculture platform designed to help smallholder farmers access post-harvest intelligence, including market prices and buyer opportunities.&lt;/p&gt;

&lt;p&gt;One of the interesting parts of the project is that a farmer can interact with the system through &lt;strong&gt;USSD&lt;/strong&gt;, without requiring a smartphone or an internet connection.&lt;/p&gt;

&lt;p&gt;The backend is built around a serverless architecture using AWS services.&lt;/p&gt;

&lt;p&gt;This article breaks down how that architecture works and what I have learned from building it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does "serverless" actually mean?
&lt;/h2&gt;

&lt;p&gt;The name can be misleading.&lt;/p&gt;

&lt;p&gt;Serverless does &lt;strong&gt;not&lt;/strong&gt; mean that there are no servers.&lt;/p&gt;

&lt;p&gt;The servers still exist. AWS manages the underlying infrastructure, while I focus on writing and deploying the application code.&lt;/p&gt;

&lt;p&gt;Instead of maintaining an always-running backend server, different parts of the application can run when they are needed.&lt;/p&gt;

&lt;p&gt;For HarvestIQ, this works particularly well because many operations are event-driven.&lt;/p&gt;

&lt;p&gt;A farmer makes a request.&lt;/p&gt;

&lt;p&gt;A function executes.&lt;/p&gt;

&lt;p&gt;Data is retrieved or updated.&lt;/p&gt;

&lt;p&gt;The function finishes.&lt;/p&gt;

&lt;p&gt;Another event can trigger another function later.&lt;/p&gt;

&lt;h2&gt;
  
  
  HarvestIQ's Serverless Architecture
&lt;/h2&gt;

&lt;p&gt;The simplified architecture looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    Farmer
                      |
                     USSD
                      |
                      v
              Africa's Talking
                      |
                      v
                AWS Lambda
                 /       \
                /         \
               v           v
          DynamoDB       Response


          EventBridge
               |
               v
          AWS Lambda
               |
               v
          Price / Alert
            Logic
               |
               v
             SNS
               |
               v
              SMS
               |
               v
             Farmer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each AWS service has a specific responsibility.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AWS Lambda&lt;/strong&gt; handles application logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DynamoDB&lt;/strong&gt; stores application data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;EventBridge&lt;/strong&gt; triggers scheduled operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SNS&lt;/strong&gt; handles notifications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Africa's Talking&lt;/strong&gt; provides the USSD and SMS connectivity layer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's look at each part.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. USSD as the Entry Point
&lt;/h2&gt;

&lt;p&gt;One of the design goals of HarvestIQ is accessibility.&lt;/p&gt;

&lt;p&gt;A farmer should not necessarily need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A smartphone&lt;/li&gt;
&lt;li&gt;A mobile application&lt;/li&gt;
&lt;li&gt;Mobile data&lt;/li&gt;
&lt;li&gt;A web browser&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A basic mobile phone with cellular connectivity can be enough.&lt;/p&gt;

&lt;p&gt;The farmer interacts with HarvestIQ through a USSD menu.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HarvestIQ

1. Check Market Price
2. List Produce
3. View Buyer Demand
4. Set Price Alert
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The USSD request is handled through the Africa's Talking USSD gateway and passed to the backend.&lt;/p&gt;

&lt;p&gt;This is where AWS Lambda comes in.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. AWS Lambda
&lt;/h2&gt;

&lt;p&gt;AWS Lambda is the compute layer of the application.&lt;/p&gt;

&lt;p&gt;Instead of maintaining a traditional server that is continuously running, I can deploy functions that execute in response to events.&lt;/p&gt;

&lt;p&gt;The basic idea is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Event
  |
  v
Lambda Function
  |
  v
Execute Code
  |
  v
Return Result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, when a farmer sends a USSD request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Farmer
   |
   v
USSD Request
   |
   v
AWS Lambda
   |
   v
Process Request
   |
   v
Return USSD Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Lambda function can also communicate with other AWS services.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Lambda
   |
   +----&amp;gt; DynamoDB
   |
   +----&amp;gt; SNS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means the application logic does not have to live on one large traditional backend server.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. DynamoDB
&lt;/h2&gt;

&lt;p&gt;HarvestIQ uses &lt;strong&gt;Amazon DynamoDB&lt;/strong&gt; as its database.&lt;/p&gt;

&lt;p&gt;This is where application data can be stored and retrieved by Lambda functions.&lt;/p&gt;

&lt;p&gt;For example, the system can store information related to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Farmers&lt;/li&gt;
&lt;li&gt;Produce listings&lt;/li&gt;
&lt;li&gt;Market prices&lt;/li&gt;
&lt;li&gt;Buyer demands&lt;/li&gt;
&lt;li&gt;Price alerts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A simplified interaction might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;USSD Request
     |
     v
Lambda
     |
     v
DynamoDB
     |
     v
Retrieve Data
     |
     v
Lambda
     |
     v
USSD Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, when a farmer requests the current price of maize, Lambda can query DynamoDB and return the relevant information through the USSD session.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. EventBridge for Scheduled Jobs
&lt;/h2&gt;

&lt;p&gt;Not everything in HarvestIQ starts with a farmer.&lt;/p&gt;

&lt;p&gt;Some operations need to happen automatically.&lt;/p&gt;

&lt;p&gt;For example, market prices may need to be updated periodically.&lt;/p&gt;

&lt;p&gt;This is where &lt;strong&gt;Amazon EventBridge&lt;/strong&gt; becomes useful.&lt;/p&gt;

&lt;p&gt;Instead of keeping a server running and writing a program that constantly waits for the next scheduled operation, EventBridge can trigger a Lambda function according to a schedule.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;EventBridge
     |
     | Scheduled Event
     v
Lambda
     |
     v
Run Price Update
     |
     v
DynamoDB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;8:00 AM  -&amp;gt; Lambda runs
10:00 AM -&amp;gt; Lambda runs
12:00 PM -&amp;gt; Lambda runs
2:00 PM  -&amp;gt; Lambda runs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact schedule depends on the application requirements.&lt;/p&gt;

&lt;p&gt;This is one of the things I found interesting about event-driven architecture: the system does not need to continuously run code just to wait for something to happen.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Understanding Amazon SNS
&lt;/h2&gt;

&lt;p&gt;This was one of the concepts I found particularly interesting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amazon SNS (Simple Notification Service)&lt;/strong&gt; is a publish/subscribe messaging service.&lt;/p&gt;

&lt;p&gt;A simple way to think about SNS is as a notification or broadcast layer.&lt;/p&gt;

&lt;p&gt;Instead of having every part of the application know exactly how to deliver a notification, an application can publish a message to an SNS topic.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
     |
     v
SNS Topic
   /   \
  /     \
SMS     Other Subscribers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In HarvestIQ, this can be useful for price alerts.&lt;/p&gt;

&lt;p&gt;Suppose a farmer sets a target price:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Produce: Maize
Target Price: ₦85,000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Later, the system checks the current market price.&lt;/p&gt;

&lt;p&gt;If the target condition is satisfied, the application can publish a notification through SNS.&lt;/p&gt;

&lt;p&gt;The flow becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;EventBridge
     |
     v
Price-check Lambda
     |
     v
DynamoDB
     |
     v
Target condition reached
     |
     v
Lambda publishes notification
     |
     v
SNS
     |
     v
SMS notification
     |
     v
Farmer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important distinction is that &lt;strong&gt;SNS is not the component deciding whether the target price has been reached&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The application logic does that.&lt;/p&gt;

&lt;p&gt;Lambda determines that the condition has been satisfied, then publishes the notification to SNS.&lt;/p&gt;

&lt;p&gt;SNS handles the notification delivery to its configured subscriber.&lt;/p&gt;

&lt;p&gt;That separation of responsibilities makes the architecture easier to reason about.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Complete Example
&lt;/h2&gt;

&lt;p&gt;Let's put everything together.&lt;/p&gt;

&lt;p&gt;Imagine a farmer wants to know the current price of maize.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: The farmer sends a USSD request
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Farmer
   |
   v
USSD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: The request reaches the backend
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;USSD
   |
   v
Africa's Talking
   |
   v
AWS Lambda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Lambda retrieves the data
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Lambda
   |
   v
DynamoDB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;DynamoDB returns the relevant market information.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Lambda generates the response
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DynamoDB
   |
   v
Lambda
   |
   v
USSD Response
   |
   v
Farmer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The entire interaction can happen without the farmer installing an application or using mobile data.&lt;/p&gt;

&lt;p&gt;Now consider a different scenario: a scheduled price update.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;EventBridge
     |
     v
Lambda
     |
     v
Fetch / Process Price Data
     |
     v
DynamoDB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if a price alert condition is reached:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Price-check Lambda
       |
       v
Target reached
       |
       v
SNS
       |
       v
SMS
       |
       v
Farmer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the part of the architecture that makes the system event-driven.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use Serverless?
&lt;/h2&gt;

&lt;p&gt;There are several reasons this architecture made sense for HarvestIQ.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Less infrastructure management
&lt;/h3&gt;

&lt;p&gt;I don't have to maintain an always-running application server myself.&lt;/p&gt;

&lt;p&gt;AWS manages much of the underlying infrastructure.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Event-driven execution
&lt;/h3&gt;

&lt;p&gt;Different parts of the application can execute in response to specific events.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;USSD request
     ↓
Lambda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Scheduled event
     ↓
Lambda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Business condition
     ↓
Notification
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Automatic scaling
&lt;/h3&gt;

&lt;p&gt;Lambda can handle multiple invocations without me manually provisioning individual servers for each request.&lt;/p&gt;

&lt;p&gt;The underlying infrastructure is managed by AWS.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Efficient use of compute
&lt;/h3&gt;

&lt;p&gt;For workloads that are intermittent or event-driven, there is less reason to maintain an application server that is continuously running just waiting for requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Serverless Is Not Perfect
&lt;/h2&gt;

&lt;p&gt;Serverless is not automatically the best architecture for every application.&lt;/p&gt;

&lt;p&gt;There are trade-offs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cold Starts
&lt;/h3&gt;

&lt;p&gt;A function that has not been invoked recently may experience additional startup latency depending on the runtime and configuration.&lt;/p&gt;

&lt;p&gt;For some applications, that latency matters.&lt;/p&gt;

&lt;h3&gt;
  
  
  Execution Limits
&lt;/h3&gt;

&lt;p&gt;Lambda functions are designed for bounded workloads rather than indefinitely running processes.&lt;/p&gt;

&lt;p&gt;That means some workloads are better suited to other architectures.&lt;/p&gt;

&lt;h3&gt;
  
  
  Distributed Debugging
&lt;/h3&gt;

&lt;p&gt;A traditional application might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client
  |
  v
Backend
  |
  v
Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A serverless application can involve many managed services:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;USSD
  |
  v
Gateway
  |
  v
Lambda
  |
  +----&amp;gt; DynamoDB
  |
  +----&amp;gt; SNS
  |
  +----&amp;gt; Other Services

EventBridge
  |
  v
Lambda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When something fails, understanding exactly where the failure occurred can require proper logging, monitoring, and tracing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Vendor Lock-in
&lt;/h3&gt;

&lt;p&gt;Using managed services deeply can also make an application more dependent on a particular cloud provider.&lt;/p&gt;

&lt;p&gt;That is an architectural decision worth considering before building at scale.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Learned
&lt;/h2&gt;

&lt;p&gt;Building HarvestIQ changed how I think about backend architecture.&lt;/p&gt;

&lt;p&gt;The biggest lesson for me is that &lt;strong&gt;serverless is less about "not having servers" and more about changing who manages the infrastructure and how application components are executed.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I also learned to think in terms of events.&lt;/p&gt;

&lt;p&gt;Instead of asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What server should always be running?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I started asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What event should cause this piece of code to run?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For HarvestIQ, those events can be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Farmer makes a USSD request
              ↓
        Lambda executes

Scheduled update occurs
              ↓
        Lambda executes

Price condition is reached
              ↓
      Notification is published
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That shift in thinking is probably the most valuable thing I have taken from building the project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;HarvestIQ started as an attempt to solve a real agricultural problem, but building it has also become an opportunity for me to learn more about cloud architecture and distributed systems.&lt;/p&gt;

&lt;p&gt;The combination of &lt;strong&gt;Lambda, DynamoDB, EventBridge, and SNS&lt;/strong&gt; gives the platform a relatively lightweight event-driven backend while allowing me to focus more on the application itself rather than server management.&lt;/p&gt;

&lt;p&gt;I'm still learning, and there are several areas I want to explore further, particularly observability, security, cost optimization, and designing more robust distributed systems.&lt;/p&gt;

&lt;p&gt;For me, this is one of the interesting parts of building software: the project solves one problem while teaching you how to solve the next one better.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>serverless</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Why the Power-of-Two Trick Works for Binary Fractions (And Why It Breaks for Everything Else)</title>
      <dc:creator>Toluwanimi Alfred</dc:creator>
      <pubDate>Thu, 18 Jun 2026 12:25:50 +0000</pubDate>
      <link>https://dev.to/alfredoeinsteino2024/why-the-power-of-two-trick-works-for-binary-fractions-and-why-it-breaks-for-everything-else-3iga</link>
      <guid>https://dev.to/alfredoeinsteino2024/why-the-power-of-two-trick-works-for-binary-fractions-and-why-it-breaks-for-everything-else-3iga</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftbac0j78g6wk6lcglfs5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftbac0j78g6wk6lcglfs5.png" alt=" " width="680" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you've taken any course that covers number systems, you've probably learned the "repeated multiplication" method for converting a decimal fraction to binary. Multiply by 2, record the digit before the decimal point, keep the remainder, repeat. It works. You can pass an exam with it. But it also feels a little like a magic trick — you follow the steps, you get the right answer, and you have no real intuition for &lt;em&gt;why&lt;/em&gt; it works or &lt;em&gt;why&lt;/em&gt; it sometimes never ends.&lt;/p&gt;

&lt;p&gt;Here's the thought process that gave me that intuition, and where it eventually breaks.&lt;/p&gt;

&lt;h2&gt;
  
  
  The starting point: 0.25
&lt;/h2&gt;

&lt;p&gt;Take 0.25. The standard method says: multiply by 2 repeatedly, record the integer parts.&lt;/p&gt;

&lt;p&gt;0.25 × 2 = 0.50 → record 0&lt;br&gt;
0.50 × 2 = 1.00 → record 1&lt;/p&gt;

&lt;p&gt;Read top to bottom: 0.25 = 0.01 in binary. Correct, but mechanical.&lt;/p&gt;

&lt;p&gt;Here's the alternative way I started thinking about it instead. 0.25 is just 1/4. And 4 is 2². So instead of multiplying repeatedly, what if I convert the numerator and denominator to binary separately, and treat the division as what it actually is — a division by a power of the base?&lt;/p&gt;

&lt;p&gt;1 in binary is 1.&lt;br&gt;
4 in binary is 100.&lt;/p&gt;

&lt;p&gt;So 1/4 is 1 / 100 in binary. And dividing by 100 (in any base) doesn't require long division if 100 is a power of that base — it just shifts the point. In decimal, dividing by 100 shifts a decimal point two places left because 100 is 10². In binary, dividing by 100₂ (which is 4 in decimal) shifts the binary point two places left for exactly the same reason: 100₂ is 2².&lt;/p&gt;

&lt;p&gt;Shift the point in "1." two places left: 0.01₂.&lt;/p&gt;

&lt;p&gt;Same answer, but now you can see &lt;em&gt;why&lt;/em&gt; it's the answer instead of just trusting the algorithm.&lt;/p&gt;

&lt;h2&gt;
  
  
  This isn't a coincidence — it's how place-value systems work
&lt;/h2&gt;

&lt;p&gt;This generalizes. Any fraction a/2ⁿ can be converted by writing 'a' in binary and shifting the point n places. 1/2 → shift 1 place → 0.1₂. 1/8 → shift 3 places → 0.001₂. 3/16 → 3 is 11 in binary, shift 4 places → 0.0011₂.&lt;/p&gt;

&lt;p&gt;It's the same logic as why dividing by 1000 in decimal is "free" (just move the point three places) — except in binary, the powers that are "free" are powers of 2, not powers of 10. This is also, not coincidentally, the entire basis of fixed-point arithmetic in embedded systems: when a microcontroller needs to represent a fraction without the overhead of a floating-point unit, it represents the value as an integer with an implicit binary point at a fixed position, and operations that would otherwise need division become bit-shifts. The "trick" above is a small, hand-worked version of that same idea.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it breaks
&lt;/h2&gt;

&lt;p&gt;The shortcut depends entirely on the denominator being a power of 2. Try it on 0.2, which as a fraction is 1/5.&lt;/p&gt;

&lt;p&gt;5 in binary is 101. 101 is not a power of 2 (it's 4 + 1, not a single power), so there's no clean shift available. To get 1/101₂ you actually have to do binary long division, and unlike 1/4, this one doesn't terminate. It repeats forever: 0.0011001100110011...&lt;/p&gt;

&lt;p&gt;This is the same underlying reason 0.1 + 0.2 doesn't exactly equal 0.3 in most programming languages — 0.1 and 0.2 are not exactly representable in binary floating point, because their denominators (10 and 5) aren't powers of 2. It's not a bug in your code; it's a structural consequence of representing base-10 fractions in a base-2 system.&lt;/p&gt;

&lt;p&gt;So the boundary is sharp: this shortcut is fast and exact for denominators of 2, 4, 8, 16, 32, and so on (equivalently, decimals like 0.5, 0.25, 0.125, 0.0625, 0.375). For anything else, you're back to repeated multiplication, and the result may never terminate.&lt;/p&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;None of this is a new method — it's a restatement of how positional number systems and fixed-point representation work, just arrived at by asking "what is this algorithm actually doing" instead of memorizing the steps. But that's worth writing down, because most people learn the multiplication method as a rote procedure and never connect it to the much more general (and much more useful) fact: in any base, dividing by a power of that base is just a point shift, and that single fact is also why certain "simple" decimal fractions can never be represented exactly in binary — a fact that quietly underlies one of the most common gotchas in floating-point programming.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>programming</category>
      <category>binary</category>
    </item>
  </channel>
</rss>
