将缓冲区的数字字符串转化成BCD码数据_INT PubNumericToBCDStr(_UCHR *pcNStr, _INT iNLen, _UCHR *pcBCDStr)
2014-03-21 15:34 夏洛克·福尔摩斯 阅读(321) 评论(0) 编辑 收藏 举报INT PubNumericToBCDStr(_CHR *pcNStr, _INT iNLen, _CHR *pcBCDStr) { _UCHR *pN = pcNStr; _UCHR *pB = pcBCDStr; _UCHR caBuffer[2]; _UCHR cHigh, cLow; _UINT iCount = 0; _UINT iNCount = iNLen / 2 + iNLen % 2; if((pcNStr == NULL) || (pcBCDStr == NULL)) { sprintf(g_caMsg,"[%s:%d] PubNumericToBCDStr input parameter error!",__FILE__, __LINE__); ErrLog(1000, g_caMsg, RPT_TO_LOG, 0, 0); return OPER_FAIL; } for( iCount = 0; iCount < iNCount; iCount++) { if ( (iCount == 0) && (iNLen%2 != 0) ) { memset(caBuffer, '\0', sizeof(caBuffer)); memcpy(caBuffer + 1, pN, 1); cHigh = (_UCHR) ((*(caBuffer + 0) - 0x30) << 4); cLow = (_UCHR) (*(caBuffer + 1) - 0x30); *pB = (_UCHR) ( cHigh + cLow ); pB += 1; pN += 1; } else { cHigh = (_UCHR) ((*(pN + 0) - 0x30) << 4); cLow = (_UCHR) (*(pN + 1) - 0x30); *pB = (_UCHR) ( cHigh + cLow ); pB += 1; pN += 2; } } return OPER_SUCC; }
技术成就现在,眼光着看未来。