关闭

类型转换

标签: delaystring
176人阅读 评论(0) 收藏 举报

//char:String.c_str()
AnsiString TForm1::BCD_to_AnsiString(char * P_BCD, int length)
{
    //TODO: Add your source code here
    AnsiString returnstring = "";
    char high_char,low_char,temp;
    for( int i=0;i<length;i++ )
    {
        temp = *P_BCD++;
        high_char = (temp&0xf0)>>4;
        low_char = temp&0x0f;

        if( (high_char>=0x00)&&(high_char<=0x09) )
            high_char+=0x30;

        if( (high_char>=0x0A)&&(high_char<=0x0F) )
            high_char+=0x37;

        if( (low_char>=0x00)&&(low_char<=0x09) )
            low_char+=0x30;
        if( (low_char>=0x0A)&&(low_char<=0x0F) )
            low_char+=0x37;

        returnstring += AnsiString(high_char);
        returnstring += AnsiString(low_char);
        returnstring += " ";
    }
    return returnstring;
}


//-------------------------------------------------------------------------------------------------------------------------

AnsiString __fastcall TMenuForm::AnsiString_To_BCD( char * P_BCD, int length )
{
    AnsiString returnstring ;
    char high_char,low_char,temp;

    for( int i=0;i<length;i++ )
    {
        temp        =   *P_BCD++;
        high_char   =   (temp&0xf0)>>4;
        low_char    =   temp&0x0f;

        if(     (high_char>=0x00)
            &&  (high_char<=0x09)
          )
        {
            high_char+=0x30;
        }

        if(     (high_char>=0x0A)
            &&  (high_char<=0x0F)
          )
        {
            high_char+=0x37;
        }

        if(     (low_char>=0x00)
            &&  (low_char<=0x09)
          )
        {
            low_char+=0x30;
        }
        if(     (low_char>=0x0A)
            &&  (low_char<=0x0F)
          )
        {
            low_char+=0x37;
        }

        returnstring += AnsiString( high_char );
        returnstring += AnsiString( low_char );
    }
    return returnstring;
}
//------------------------------------------------------------------------------------------------------------------------------------------
//十进制转为BCD
int __fastcall TForm1::ConvertBCD(int dnum)
{
  int  bcdval=0;
  if( dnum>9999 || dnum < 0 )   return   -1;  
  bcdval   =   (( (dnum/1000)*16+(dnum%1000)/100)*16+(dnum%100)/10   )*16 + dnum%10;
  return   bcdval;  
}
//------------------------------------------------------------------------------------------------------------------------------------------
//BCD转十进制
StrToInt("0x"+BCD_String);
//--------------------------------------------------------------------------------------------------------------------------------------------
再附一个时间延迟函数
//---------------------------------------------------------------------------
//时间延迟函数,单位是毫秒
void __fastcall TForm1::Delay(DWORD DT)
{
    DWORD BeginTime;

    BeginTime = GetTickCount();
    do
    {
        Application->ProcessMessages();
    }while( GetTickCount() - BeginTime <= DT );
}
//-------------- 
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:5593次
    • 积分:140
    • 等级:
    • 排名:千里之外
    • 原创:8篇
    • 转载:2篇
    • 译文:0篇
    • 评论:0条
    文章存档