1.QByteArray ba;
ba.resize(5);
ba[0] = 0x3c;
ba[1] = 0xb8;
ba[2] = 0x64;
ba[3] = 0x18;
ba[4] = 0xca;
QByteArray 支持判断信息类型。。。并且初始化0x -也就是16进制
2.直接强制换。。。
十进制->十六进制 i=1024;
ltoa(i,h,16);
sprintf(hs,"%08s",h);
printf("i=%d,hs=%s\n",i,hs);
二进制-十六进制 strcpy(bs,"00000000000000000000010000000000");
i=strtol(bs,&e,2);
ltoa(i,h,16);
sprintf(hs,"%08s",h);
printf("bs=%s,hs=%s\n",bs,hs);
字符-十六进制 strcpy(s,"a汉");
i=0;
while (1) {
if (0==s[i]) break;
sprintf(hs+i*2,"%02X",(unsigned char)s[i]);
i++;
}
setlocale(LC_ALL,"chs");
printf("s=%s,hs=%s\n",s,hs);
|