Qt下发送十六进制的方法

 

QByteArray ba=ui->lineEdit->document()->toPlainText().toAscii();

int hlong=0,hloop=0;
            QByteArray outarray;
            outarray.resize(0);
            for(hloop=0;hloop             {
                if(((ba[hloop].operator <=(0x39))&&(ba[hloop].operator >=(0x30)))||((ba[hloop].operator<=(0x5A))&&(ba[hloop].operator>=(0x41)))||((ba[hloop].operator<=(0x7A))&&(ba[hloop].operator>=(0x61))))
                {
                    hlong++;
                    outarray.resize(hlong);
                    if((ba[hloop].operator<=(0x39))&&(ba[hloop].operator>=(0x30)))
                        outarray[hlong-1]=(ba[hloop]-48)<<4;
                    else if((ba[hloop].operator<=(0x5A))&&(ba[hloop].operator>=(0x41)))
                        outarray[hlong-1]=(ba[hloop]-55)<<4;
                    else if((ba[hloop].operator<=(0x7A))&&(ba[hloop].operator>=(0x61)))
                        outarray[hlong-1]=(ba[hloop]-87)<<4;

                    if((ba[hloop+1].operator<=(0x39))&&(ba[hloop+1].operator>=(0x30)))
                        outarray[hlong-1]=outarray[hlong-1]+ba[hloop+1]-48;
                    else if((ba[hloop+1].operator<=(0x5A))&&(ba[hloop+1].operator>=(0x41)))
                        outarray[hlong-1]=outarray[hlong-1]+ba[hloop+1]-55;
                    else if((ba[hloop+1].operator<=(0x7A))&&(ba[hloop+1].operator>=(0x61)))
                        outarray[hlong-1]=outarray[hlong-1]+ba[hloop+1]-87;
                }
                else if(ba[hloop].operator==(0x0A))
                {
                    outarray[hlong-1]=ba[hloop];
                    hlong++;
                    outarray.resize(hlong);
                    outarray[hlong-1]='\r';
                }
            }           

 

你可能感兴趣的:(qt)