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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 1, 2025

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

      June 1, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 1, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 1, 2025

      My top 5 must-play PC games for the second half of 2025 — Will they live up to the hype?

      June 1, 2025

      A week of hell with my Windows 11 PC really makes me appreciate the simplicity of Google’s Chromebook laptops

      June 1, 2025

      Elden Ring Nightreign Night Aspect: How to beat Heolstor the Nightlord, the final boss

      June 1, 2025

      New Xbox games launching this week, from June 2 through June 8 — Zenless Zone Zero finally comes to Xbox

      June 1, 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

      Student Record Android App using SQLite

      June 1, 2025
      Recent

      Student Record Android App using SQLite

      June 1, 2025

      When Array uses less memory than Uint8Array (in V8)

      June 1, 2025

      Laravel 12 Starter Kits: Definite Guide Which to Choose

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

      My top 5 must-play PC games for the second half of 2025 — Will they live up to the hype?

      June 1, 2025
      Recent

      My top 5 must-play PC games for the second half of 2025 — Will they live up to the hype?

      June 1, 2025

      A week of hell with my Windows 11 PC really makes me appreciate the simplicity of Google’s Chromebook laptops

      June 1, 2025

      Elden Ring Nightreign Night Aspect: How to beat Heolstor the Nightlord, the final boss

      June 1, 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.

    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

    My top 5 must-play PC games for the second half of 2025 — Will they live up to the hype?

    June 1, 2025
    News & Updates

    A week of hell with my Windows 11 PC really makes me appreciate the simplicity of Google’s Chromebook laptops

    June 1, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Distributed training and efficient scaling with the Amazon SageMaker Model Parallel and Data Parallel Libraries

    Development

    Bio-xLSTM: Efficient Generative Modeling, Representation Learning, and In-Context Adaptation for Biological and Chemical Sequences

    Machine Learning

    British Prime Minister wants access to messaging apps

    Development

    This Nintendo Switch bundle is just $360 at Amazon ahead of Black Friday

    Development

    Highlights

    15 Design Concepts Every Financial Product Owner Should Know and Use

    August 19, 2024

    Financial and banking product owners face complex challenges and must stay ahead by implementing key…

    This AI Paper from Microsoft and Oxford Introduce Olympus: A Universal Task Router for Computer Vision Tasks

    December 22, 2024

    Are tariffs about to make your next iPhone way more expensive? It’s complicated

    April 4, 2025

    New Wave of JSOutProx Malware Targeting Financial Firms in APAC and MENA

    April 5, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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