Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22048

How to convert string representation of an arbitrary length integer in a given base to decimal?

$
0
0

I was wondering how would you convert an arbitrary length integer integer in some base b represented by a string into a string representation in base 10.

To give you an example, if I send the string "4552" and I also send that it's in base 8, and I want to convert this string into base 10 and return the string but I can't use things like atoi or strtol because if I'd send 312434324324324324324324 It'd be impossible, I first thought you can use like a classical recursive algorithm that do a recursive with the number % 10 until last digit, then reversely putting the number into a string.

Anyway, I'm actually kind of lost and I don't know how is that possible, if you guys have any hints or ways I can do it. I let you the prototype of my function so that you can have the basics, thanks.

char *to_base_10(char *nb, int base)
{
    int size = my_strlen(nb);
}

Viewing all articles
Browse latest Browse all 22048

Trending Articles