Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7702327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:12:08+00:00 2026-05-31T23:12:08+00:00

I’m currently building a converter in C#. My program is converting from/to Decimal, Binary

  • 0

I’m currently building a converter in C#. My program is converting from/to Decimal, Binary and Hexadecimal. My problem is that in some specific cases the result is not correct.

Examples:

FFFFF (hexa) to Decimal = 148575 (Real answer: 1048575)

20000 (decimal) to Decimal = 20 (Real answer: dont need a calculator :P)

Also I can’t use any Convert.ToString as it is for school and my teacher asked us to manipulate the variables and play with functions.

I think my convertToString() function causes the problem of losing zeros somewhere.

private string convertToString(int value)
{
    string result = "";
    string tmp = "";
    int y = 0;

    while (value != 0) {
        int valeur = value;
        y = 0;
        while (valeur > 9) {
            valeur = valeur / 10;
            y++;
        }
        switch (valeur) {
            case 0:
                tmp = "0";
                break;
            case 1:
                tmp = "1";
                break;
            case 2:
                tmp = "2";
                break;
            case 3:
                tmp = "3";
                break;
            case 4:
                tmp = "4";
                break;
            case 5:
                tmp = "5";
                break;
            case 6:
                tmp = "6";
                break;
            case 7:
                tmp = "7";
                break;
            case 8:
                tmp = "8";
                break;
            case 9:
                tmp = "9";
                break;
        }
        value = (int)(value - (valeur * Math.Pow(10, y)));
        result = result + tmp;
    }

    if (y != 0) {
        result = result + "0";
    }
    return result;
}

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:12:10+00:00Added an answer on May 31, 2026 at 11:12 pm

    The problem is that you create confusion with two names meaning the same in English and French: value / valeur;

    You would calculate the decimal places like this

    string result = "";
    bool minus = false;
    if (value == 0 ) {
        result = "0";
    } else {
        // Begin the string with a minus (`-`) if value is negative
        // and continue the conversion with a positive value.
        if (value < 0) {
             minus = true;
             value = - value;
        }
    
        // Add decimals to the result as long as the remaining number is not zero.
        while (value > 0) { 
            // Get last decimal using the modulo operator
            int lastDecimal = value % 10;
    
            // Prepend the decimal to the result after having converted it to a character
            result = (char)('0' + lastDecimal) + result;
    
            // Divide the value by 10. Integer division!
            value = value / 10;
        }
        if (minus) {
            result = "-" + result;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.