#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <ctype.h>
#include <string.h>
setlocale(LC_ALL, "");
char *str = "http中国人民hello";
wchar_t * p = (wchar_t *)malloc(sizeof(wchar_t) * 100);
memset(p, L'\0', 100 * sizeof(wchar_t));
mbstowcs(p, str, 99);
char * tmp = (char *)malloc(sizeof(char) * 20);
char * tmp1;
while (*p != L'\0') {
sprintf(tmp, "%x", *p);
//将16进制字符串转为10进制的整型
int n = (int)strtol(tmp, &tmp1, 16);
printf("%s=%d\n", tmp, n);
p++;
}
转载于:https://my.oschina.net/u/3132973/blog/818693