解决方案 »

  1.   

    函数上面还有一部分代码:
    void CFactionSet::EditSend(int row,CString str)
    {
    char temp[2]={0x0}; if (row==116||row==117)
    {
    char *str1=(char*)malloc(1);
    temp[1]=0x00;
    str1=(LPSTR)(LPCTSTR)str;
    temp[0]=*str1;
    } else 
    {
    str.Replace("%",NULL);
    if (str.GetAt(0)=='-')
    {
    str.Replace("-",NULL);
    float num=atof(str.GetBuffer(0));
    temp[0]=*MultUpling(row,num);
    temp[1]=*(MultUpling(row,num)+1);
    temp[0]=~temp[0];
    temp[0]=temp[0]|0x80;
    temp[1]=~temp[1];
    temp[1]=temp[1]+1;
    if (temp[1]==0x0)
    {
    temp[0]+=1;
    }
    }
    else
    {
    float num=atof(str.GetBuffer(0));
    temp[0]=*MultUpling(row,num);
    temp[1]=*(MultUpling(row,num)+1);
    }
    }

    CMainFrame *m_MainFrame=new CMainFrame;
    unsigned char tempTo[6]={0x01,0x06};
        tempTo[3]=(unsigned char)m_row;
    tempTo[4]=(unsigned char)temp[0];
    tempTo[5]=(unsigned char)temp[1];
    unsigned char b[sizeof(tempTo)*2]={0};
    unsigned long outlen=sizeof(tempTo)*2;

    m_MainFrame->byte2hex(tempTo,sizeof(tempTo),b,&outlen);

    CString temp1=b;
    temp1=temp1.Left(temp1.GetLength()-2);
        
    CString temp2=m_MainFrame->crcString(tempTo,sizeof(tempTo));
    temp2=temp2.Left(4);
    temp1+=temp2;

    temp1=m_MainFrame->ChangeCharstr2Hexstr(temp1);
    m_SerialPort.WriteToPort(temp1.GetBuffer(temp1.GetLength()),temp1.GetLength());
    delete m_MainFrame;}LPSTR CFactionSet::MultUpling(int row,float num)
    {
    float num0=0.0;
    if (CompareEditMul1(row)!=65535)
    {
    num0=num;
    }
    else if (CompareEditMul10(row)!=65535)
    {
    num0=num*10;
    }
    else if (CompareEditMul100(row)!=65535)
    {
    num0=num*100;
    }
    else if (CompareEditMul1000(row)!=65535)
    {
    num0=num*1000;
    }
    int num1=(int)num0;
    return HexExchange(num1);
    }
      

  2.   

    搞这么复杂,给个我写的试验函数,10进制转N进制,其中 jz=进制,16进制时 jz=16// 十转N进制
    CString CNumChangeDlg::ChangNub(__int64 def,int jz)
    {
    int tn=0; // 未数
    __int64 tz=0;
    CString str=_T(""); tn=def%jz;
    tz=def/jz;
    str=DotToStr(tn);
    for(int i=0;;i++)
    {
    tn=tz%jz;
    tz=tz/jz;
    str=DotToStr(tn)+str;
    if(tz<jz)
    break;
    }
    str=DotToStr(tz)+str;
    // 去掉前导0
    CString h;
    for(;;)
    {
    h=str.Left(1);
    if(h==_T("0"))
    str=str.Right(str.GetLength()-1);
    else
    break;
    } return str;
    }