Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 3, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 3, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 3, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 3, 2025

      All the WWE 2K25 locker codes that are currently active

      June 3, 2025

      PSA: You don’t need to spend $400+ to upgrade your Xbox Series X|S storage

      June 3, 2025

      UK civil servants saved 24 minutes per day using Microsoft Copilot, saving two weeks each per year according to a new report

      June 3, 2025

      These solid-state fans will revolutionize cooling in our PCs and laptops

      June 3, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Community News: Latest PECL Releases (06.03.2025)

      June 3, 2025
      Recent

      Community News: Latest PECL Releases (06.03.2025)

      June 3, 2025

      A Comprehensive Guide to Azure Firewall

      June 3, 2025

      Test Job Failures Precisely with Laravel’s assertFailedWith Method

      June 3, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      All the WWE 2K25 locker codes that are currently active

      June 3, 2025
      Recent

      All the WWE 2K25 locker codes that are currently active

      June 3, 2025

      PSA: You don’t need to spend $400+ to upgrade your Xbox Series X|S storage

      June 3, 2025

      UK civil servants saved 24 minutes per day using Microsoft Copilot, saving two weeks each per year according to a new report

      June 3, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Consultant Conversions

    CodeSOD: Consultant Conversions

    January 20, 2025

    Janet‘s company had a glut of work, and thus didn’t have the staffing required to do it all. It didn’t make sense to hire on any new full-time employees, so they went the route of bringing on a few highly paid consultants, specifically ones who specialized in one specific problem: talking to a piece of hardware purchased from a vendor.

    The hardware in question was a scientific which communicated over a serial line. This device provided a lot of data that represented decimal values, but that data was not encoded as an IEEE float. Instead, they used two integers- one for the data, and one representing the number of decimal places.

    So, for example, “555.55” would be represented as “55555 2”.

    Now, in embedded devices, this isn’t too unusual. It’s entirely possible that the embedded CPU didn’t even support true floating point operations, and this was just how they decided to work around that.

    When communicating over the serial line, the device didn’t send the data encoded in binary, however- it did everything as text. This was arguably helpful as it meant a technician could communicate with the device directly over a terminal emulator, but it meant any software talking to the device had to parse data.

    Which brings us to the code written by the highly paid consultants. This code needs to take two 16-bit integers and turn them into a single decimal value. Let’s see how they did it.

    /// <summary>
    /// Sets the single parameter value.
    /// </summary>
    /// <param name="Value">Name of the parameter.</param>
    /// <param name="decimals"></param>
    /// <returns></returns>
    public double ConvertIntToDecimal(string Value, string decimalCount)
    {
        double Result;
    
        var decimals = UInt16.Parse(decimalCount);
        var Val = UInt16.Parse(Value);
        if (decimals > 0)
        {
            var divider = Math.Pow(10, decimals);
            Result = ((float)Val) / divider;
        }
        else
        {
            Result = Val;
        }
    
        return Result;
    }
    

    We start with comments that are just wrong, which is always a good start. The whole thing has delightfully randomized capitalization- a mix of PascalCase and camelCase.

    In the core logic, we parse the input values, and if there are any decimal places, we do some arithmetic to build our floating point value. We get the fun bonus inconsistency of casting to float when we handle our result in double, but at least it’s a widening inconsistency, I suppose.

    Hostinger

    As an overall approach to the problem, it’s not a train wreck, but there’s one very important thing that our highly paid consultant forgot. Our HPC, remember, was an expert in this particular instrument, or at least that was their claim. And while their mistake is an easy mistake to make while coding, it should also be an easy mistake to catch during testing, too.

    What was the mistake?

    The value is frequently negative, and they’re using UInt16 to parse the inputs. Which means this function frequently threw an exception. Literally five minutes of testing would have turned it up. Janet had piles of sample data, recorded from the device, which she used for testing. Almost all of her test cases would trigger the bug at some point.

    It seems likely, at this juncture, that the HPC simply never actually tested the code. They wrote it. They committed it. They collected their check and left. Janet may have been the first person to actually run the code at all.

    In the end, hiring the HPC cost a lot of money, and maybe saved a few days of work over the course of months. It’s hard to say, as it may have created more work, since so much of what the HPC did had to be debugged and often rewritten.

    The “good” news is that they have another glut of work, so management is looking to bring back the consultants for another round.

    [Advertisement] Plan Your .NET 9 Migration with Confidence
    Your journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous Articlekazv – convergent Matrix client and secure messaging app
    Next Article timr – TUI to organize your time

    Related Posts

    News & Updates

    All the WWE 2K25 locker codes that are currently active

    June 3, 2025
    News & Updates

    PSA: You don’t need to spend $400+ to upgrade your Xbox Series X|S storage

    June 3, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    It’s time for design to think less and feel more

    Web Development

    pEBR: A Novel Probabilistic Embedding based Retrieval Model to Address the Challenges of Insufficient Retrieval for Head Queries and Irrelevant Retrieval for Tail Queries

    Development

    Is this Windows 11 ‘bug’ the feature we’ve been waiting for? Say goodbye to Copilot (for now)

    News & Updates

    ERROR_HIBERNATION_FAILURE: How to Fix This BSoD Error?

    Operating Systems

    Highlights

    Artificial Intelligence

    Creating and verifying stable AI-controlled systems in a rigorous and flexible way

    July 27, 2024

    Neural networks have made a seismic impact on how engineers design controllers for robots, catalyzing…

    King Arthur: Legion IX Set to Launch on Xbox Series X|S on May 6, 2025

    April 20, 2025

    This $280 Android phone just set a new standard for budget handsets – and it looks great

    April 28, 2025

    You can get the Amazon Fire HD 8 Plus for over 50% off with this trade-in deal

    August 23, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.