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

6 Years
Discussion Span
Last Post by doctorkasim

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

Edited by Narue: n/a


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..


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)

    while (value != 0) {
        result.insert(result.begin(), (value % 2) + '0');
        value /= 2;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.