C++ BCD转码问题

//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 );
}

你可能感兴趣的:(C++,String,delay)