1. 程式人生 > >十進位制轉換成十六進位制字串

十進位制轉換成十六進位制字串

void InttoHex() 
{
int num = 198;
int idex;
char str[16];
int i = 0,j;
char c;
char hex[]= {'A','B','C','D','E','F'};
while (num) {
idex = num % 16;
num /= 16;
if (idex >=10) {
str[i++] = hex[idex-10];
continue;
}
str[i++] = idex + '0';
}
str[i] = '\0';
int len = strlen(str);
for (j = 0; j < len; j++)
{
c = str[j];
str[j] = str[len-1];
str[len-1] = c;
len--;
}
printf("-----%s\n",str);
}