I'v got this got to work for binary and deciaml by change it to a 2 or a 10 for the base, but when I use 16 for Hex, it doesn't produce the correct results for some reason. Any ideas?

Code:

if(base =='h')
{
int temp = x, quotient, remainder;
int count = 0;
int i;
int p;
int q;
do{
quotient = temp/16; //base
temp = quotient;
count++;
}
while(quotient != 0);
count++;
temp = x;
//char *aray = new char[count];
for(p=0, q=count-2; p<count-1; p++, q--)
{
quotient = temp / power(16, q); //base
remainder = temp % (int)power(16, q); //base
string[p] = quotient+48;
temp = remainder;
}
string[p] = 0;//giving null character to last element of aray.
return x;
}