zoukankan      html  css  js  c++  java
  • 将缓冲区的数字字符串转化成BCD码数据_INT PubNumericToBCDStr(_UCHR *pcNStr, _INT iNLen, _UCHR *pcBCDStr)

    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, '', 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;
    }
    

      

  • 相关阅读:
    Python模块笔记
    js日期
    js字符串
    js數字
    js對象構造
    js 錯誤
    js break和continue
    js條件結構和循環結構
    js運算符
    js函數
  • 原文地址:https://www.cnblogs.com/sherlockhomles/p/3616010.html
Copyright © 2011-2022 走看看