16,472
社区成员
发帖
与我相关
我的任务
分享
//
BYTE HexValue(BYTE a)
{
a -= 48;// '0' 0x30
if(a >32) a -=32;// 'a' 0x61
if(a > 9 ) a -= 7;// 'A' 0x41
return a;
}
//
BYTE Hex2Bytes(BYTE s[2])
{
BYTE v=0;
for(int ii=0 ;ii<2; ii++)
{
v <<=4;
v += HexValue(s[ii]);
}
return v;
}
void CxxxxDlg::OnButton3()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_Edit.Replace(" ","");
// afxDump << m_Edit << "\n";
int len=m_Edit.GetLength();
if((len %2 )!=0) return; // error
// afxDump << len << "\n";// 28
//
BYTE *pData=new BYTE[len];// 2 bytes to 1 byte
CString tmp;
for(int kk=0;kk<len/2;kk++)
{
tmp=m_Edit.Mid(kk*2,2);
afxDump << tmp << "\n";
pData[kk]=Hex2Bytes((BYTE*)tmp.GetBuffer(2));
afxDump << pData[kk] << "\n";
}
pData[kk]=0;
afxDump << (char*)pData << "\n";
if(pData) delete [] pData;
}