字符串转整数使用sscanf
int value = 0; char *buf = "1d5ce"; sscanf (buf, "%x", &value); printf ("Hex value is:%x ", value);
整数转字符串使用sprintf
int num = 0; char buf[10] = {}; num = 120270; sprintf (buf, "%x", num); //打印 buf 是:1d5ce 就是把 num 转换成十六进制值,以字符串方式存储在 buf 中