十进制或十六进制转字符串
作者:互联网
参数
dest : 目标字符串型内存
sour: 十进制或十六进制整数
rate:进率(10 or 16)
int ixtoa(char *dest, int sour, int rate)
{
char tmp[16] = {0};
int i = 0, j = 0;
while(sour)
{
j = sour % rate;
if(j < 10)
tmp[i] = j + '0';
else
tmp[i] = j - 10 + 'a';
sour = sour / rate;
i++;
}
if(rate == 16)
{
tmp[i++] = 'x';
tmp[i++] = '0';
}
j = 0;
while(i)
{
dest[j] = tmp[i-1];
j++, i--;
}
dest[j] = 0;
return 0;
}
标签:tmp,十六进制,int,dest,++,rate,sour,字符串,十进制 来源: https://blog.csdn.net/dongtaintailiang/article/details/99678103