#include <stdio.h> #include <stdlib.h> //字符串直接转换成16进制 int main(int argc, const char* argv[]) { long ret; char src[64] = {0}; for(;;) { scanf("%s", src); ret = strtol(src, NULL, 16); printf("%0x = %ld\n", ret, ret); } return 0; } 测试结果