[Solved]Convert ASCII hex to int
-
I tried this:
{ // iterate over all the matchesconst QRegularExpressionMatch hexMatch = i.next(); qDebug() << hexMatch.capturedRef(0) << hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16); //capturedRef contains the part matched by the regular expression y1.append(hexMatch.capturedRef(1).toUInt(Q_NULLPTR,16)); y2.append(hexMatch.capturedRef(2).toUInt(Q_NULLPTR,16)); y3.append(hexMatch.capturedRef(3).toUInt(Q_NULLPTR,16)); y4.append(hexMatch.capturedRef(4).toUInt(Q_NULLPTR,16)); }
-
yes I see that it is a loop but if i write :
if(eingangMatch.hasMatch()) { if(eingangMatch.capturedRef(1).compare("80",Qt::CaseInsensitive)==0) { // Eingang==("80:") qDebug() << eingangMatch; for(QRegularExpressionMatchIterator i = hexRegExp.globalMatch(line); i.hasNext(); ) const QRegularExpressionMatch hexMatch = i.next(); qDebug() << hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16); //capturedRef contains the part matched by the regular expression y1.append(hexMatch.capturedRef(1).toUInt(Q_NULLPTR,16)); y2.append(hexMatch.capturedRef(2).toUInt(Q_NULLPTR,16)); y3.append(hexMatch.capturedRef(3).toUInt(Q_NULLPTR,16)); y4.append(hexMatch.capturedRef(4).toUInt(Q_NULLPTR,16)); }
the qDebug() << eingangMatch; and qDebug() << hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16);
don't work and all my y vectors get "0"
"80: 1C 05 3A 85 FF 4F FF 1D 89 1E 08 10 01 00 00 00 3B 87 51 01 AF 00 58 09 88 10 00 00 "
QVector(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
QVector(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) -
@Leopold said in [Solved]Convert ASCII hex to int:
yes I see that it is a loop
I don't think you do...
int h=0; for(QRegularExpressionMatchIterator i = hexRegExp.globalMatch(line);i.hasNext();++h){ const QRegularExpressionMatch hexMatch = i.next(); qDebug() << hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16); switch(h){ case 1 : y1.append(hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16)); break; case 2 : y2.append(hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16)); break; case 3 : y3.append(hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16)); break; case 4 : y4.append(hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16)); break; default: break; } }