C 16进制去掉0x转换成字符串输出

int main() { long val = 0; long sum[20] = {0}; char buf[20] = {0}; int index = 0; scanf("%x", &val); while(val > 0) { sum[index] = val%16; val /= 16; index++; } int iCount = 0; while(index--) { if(sum[index] > 9) { buf[iCount] = sum[index] + 55; } else { buf[iCount] = sum[index] + 48; } iCount++; } printf("%s/n", buf); return 0; } 

你可能感兴趣的:(C 16进制去掉0x转换成字符串输出)