i know basic question i'm newbie in qt , don't know it. i'm trying convert qstring value (like "aa110011") hexadecimal. obtain 0xaa110011. i've tried code:
qbytearray b = astring.toutf8(); (int = 0; < b.length(); i++ ) { if ( b[i] >= 65 && b[i] <= 70 ) { b[i] = b[i] - 55; } else if (b[i] >= 48 && b[i] <= 57) { b[i] = b[i] - 48; } }
i obtain in memory @ vairable "[0]" value 0a 0a 01 01 00 00 01 01 , don't know how obtain aa 11 00 11.
could me? thanks.
try qstring::toint, qstring::touint, qstring::tolong etc., example:
const qstring str = qlatin1string("aa110011"); bool ok; const unsigned int parsedvalue = str.touint(&ok, 16); if (!ok) { //parsing failed, handle error here } qdebug() << parsedvalue;
the second argument base, 16 in case hexadecimal.
this solution work if string fits unsigned long long or shorter - not work if want convert arbitrarily long strings way.
Comments
Post a Comment