#include <stdio.h>
#include <string.h>
#include <iostream.h>
typedef unsigned char BYTE;
typedef unsigned int UINT ;
typedef unsigned char UCHAR;
void Byte2Hex(BYTE *pbSrc, char *szDst, UINT uLen);
int main()
{
char szDst[256] = {0};
BYTE bSrc[] = {0xec, 0xff, 0xce, 0xac, 0x52, 0xe4};
Byte2Hex(bSrc, szDst, sizeof bSrc / sizeof BYTE);
cout<<szDst<<"\n";
return 1;
}
void Byte2Hex(BYTE *pbSrc, char *szDst, UINT uLen)
{
char strtemp[16];
UCHAR b[64] = {0};
for(UINT k = 0; k < uLen; k++)//转换为BYTE型数组
{
BYTE bt=*(char*)(pbSrc + k); //字符型
memset(strtemp, 0, 16);
//将字符以十六进制方式送入临时变量strtemp存放,注意这里加入一个空隔
sprintf(strtemp, "%02x ", bt);
//strtemp.Format("%02x ", bt);
strcat(szDst, strtemp); //加入接收编辑框对应字符串
}
}