例如
cc953a161035
#include <stdio.h> #include <string.h> int main() { char hex[200]; char s[100]; strcpy(hex,"98e1e97b3294cd43260aa8766dd21b9e354f5926d34f9b5fa510e84937316992a740a46b41d3e4fbe4ec285b2bc992db5f12d3cc0388e726b00f80fadd73f77846b40e8c75bb90739a484ec60a2c38422411f418e5ae075ac16194a3b1a60bd3"); int L=strlen(hex), i, v; for (i=0;i<L/2;i++) { sscanf(hex+i*2,"%2X",&v); s[i]=(char)(v&0xFFu); } s[i]=0; printf("%s\n",s); L=strlen(s); for (i=0;i<L;i++) sprintf(hex+2*i,"%02x",(unsigned char)s[i]); hex[2*i+2]=0; printf("%s\n",hex); }
以上代码输出: