Convert int to string with number in different base

How would you go about converting an int to a string which represents the same number in a different base?

In my case, I have to convert a number to PENTAdecimal (not hexadecimal), which is base 15. It must be a standard C++ function though.

Thanks in advance,
Anonymouse
Non-standard.
The base conversion can be done with a two-step algorithm.

Start with a decimal number, n.
1) n%15 yields the least significant digit of the pentadecimal number
2) n /= 15.
Repeat this process. The second iteration will yield the second least significant digit, and so on and so forth. The iteration when n finally equals zero will yield the final and most significant digit.

To create a string which represents that number, you could start with a char array that stores the characters 0-E such that the position in the array equals the decimal value of that character (i.e '0' in array[0], 'C' in array[12]). To create your string, refer to step 1 in the algorithm. Insert that element of the array at the beginning of your string.
Sorry, you're confusing me...
:(
You won't find a standard function that will perform this operation, so you need to write one. This shows exactly what the function needs to do: http://mathforum.org/pcmi/hstp/sum2001/wg/number.theory/session02.pdf

To convert the numbers into characters, I suggested something like:
1
2
3
4
char digit[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E'};

int i = 13;
char c = digit[i]; // c = 'D' , which is 13 in decimal 

The problem is, I'm handling numbers with sizes between 0 and 512. That takes a long time to write an array... I'd like to have a simple option like that...
I think you misunderstand what I was trying to show. The array of characters in my example is analogous to the alphabet; you can write a very long sentence, or even an entire novel, but you still only use the 26 letters of the alphabet. Likewise, regardless of the length of a pentadecimal number, you will only ever use the digits 0-E.
Topic archived. No new replies allowed.