汉字字符串与16进制互转

#include
#include
int main()
{
    char z[20]="我";
    char hex[100]="";
    //汉字转16进制
    unsigned int len=strlen(z);
    int i=0;
    for(;i=0x80的字符的16进制就会多6个f
        sprintf(hex+2*i,"%x",z[i]&0xff);
    printf("%s\n",hex);
    //16进制转字符串
    len=strlen(hex);
    char tem[2]="";
    for(i=0;i         memcpy(tem,hex+i,2);
        sscanf(tem,"%x",z+i/2);
    }   
    printf("%s\n",z);
}

你可能感兴趣的:(Linux)