Any one would help me out to develop a code for a program to convert number from any base to any base..?

Recommended Answers

All 6 Replies

Help comes to those who first help themselves. In other words, what have you done so far?

according to the logic designed so far by me,i convert numbers from any base to decimal system but failed to convert it further from decimal to the any required base..

Post your code then. Converting from any base to decimal is a good start.

Can you tell me how i can combine the remainders by repeated division of single digit.For example when 29 is repeatedly divided by 2 then remainders are 1,0,1,1...
I hope you understand the problem

It depends on how you plan to represent the result. This is especially important when converting from base 10 to base 2, because if you're planning on storing the result in an integer type, you can't cover the full range. For example, the largest 32-bit value is ten digits, but the binary representation of that value is 32 digits.

Ideally you would store the represented value as a string and then convert as necessary for calculations. In that case, it's a simple matter of prepending a string with each digit (or appending and reversing at the end):

void dtob(int value, std::string& result)
{
    result.clear();

    while (value != 0) {
        result.insert(result.begin(), (value % 2) + '0');
        value /= 2;
    }
}

Thanks for your kind help..Have a nice time

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.