经过近几天尝试了多种方法,可以通过以下三种方式实现16进制转成中文输出,utf8编码占3个字节,gb2312编码占2个字节,具体方法如下:
方法一:
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
unsigned char ch2hex(char ch)
{
static const char* hex = "0123456789abcdef";
for (unsigned char i = 0;i != 16;++i)
if (ch == hex[i])
return i;
return 0;
}
char* solve(char* dest, const char* src)
{
int i = 0;
int cnt = 0;
unsigned char* d = (unsigned char*)dest;
while (*src)
{
if (i & 1)
{
d[cnt++] |= ch2hex(*src);
}
else
{
d