Qt 6.11 is out! See what's new in the release
blog
Convert 0xAABBCCDD to QString DDCCBBAA
-
Hello,
I need to convert for example from int 0xAABBCCDD to QString DDCCBBAA. I think it's any function of QByteArray but I can't find more.I have this code, but It doesn't work properly, output is last two letters.
#define NUMBER 0xAAFC QByteArray array; array.append(NUMBER); qDebug() << QString(array.toHex());Thanks for help, byte actions aren't my friends.
-
The fact that you used symmetric bytes (e.g. AA instead of A1) makes it somewhat ambiguous. See if this suits you
QString hexString = QString::number(0xA1B2C3D4,16); std::reverse(hexString.begin(),hexString.end());this will produce
4D3C2B1Aif you wanted
D4C3B2A1instead you can indeed use bitshift:QString hexString; for(auto number = 0xA1B2C3D4;number;number >>=8) hexString.append(QString::number(number & 0xFF,16));EDIT
Fixed error in code
-
The fact that you used symmetric bytes (e.g. AA instead of A1) makes it somewhat ambiguous. See if this suits you
QString hexString = QString::number(0xA1B2C3D4,16); std::reverse(hexString.begin(),hexString.end());this will produce
4D3C2B1Aif you wanted
D4C3B2A1instead you can indeed use bitshift:QString hexString; for(auto number = 0xA1B2C3D4;number;number >>=8) hexString.append(QString::number(number & 0xFF,16));EDIT
Fixed error in code