2,640
社区成员
发帖
与我相关
我的任务
分享
bool StrToBCD(char *pSource, BYTE *pDest, int nCount)
{
int nBCDByte = nCount >> 1;
int nLastChar = strlen(pSource);
int nFirst = nCount - nLastChar;
char c;
nLastChar--;
if (nFirst < 0)
return false;
memset(pDest, 0, nBCDByte);
for (int i = nCount-1; i >= nFirst; i--)
{
if (pSource[nLastChar] < 0x30 || pSource[nLastChar] > 0x39)
return false;
else
c = pSource[nLastChar--];
c &= ~0x30;
if (!(i%2))
c <<= 4;
pDest[i>>1] |= c;
}
return true;
}