(QByteArray::fromHex("a").toHex() == QByteArray("a")) false?!
-
Would you expect the above to be true?
I tried the following and the results are puzzling me.
@
qDebug() << (QByteArray::fromHex("a").toHex() == QByteArray("a")); // false
qDebug() << QByteArray::fromHex("a").toHex(); // 0a
qDebug() << QByteArray::fromHex("aa").toHex(); // aa
qDebug() << QByteArray::fromHex("aaa").toHex(); // 0aaa
@I'm a bit confused... What do you think?
-
Looks ok to me.
When you call toHex(), QBA translates the symbol into a hex value (1 byte, hence the '0a' you get in line 2 and 4).
Line 1 is fine because you are comparing a value converted into hex with a string "a". Remember: "a" != 'a' != 0xa
-
Hi,
Did you try "fromHex":http://qt-project.org/doc/qt-4.8/qbytearray.html#fromHex ?
-
fromHex/toHex works quite well with a even number of hex-digits.
But with odd numbers there's always the leading zero.I think I understand the problem now.
One character takes only half a byte. So if there is an odd number of characters there must be 4 bits padded. These are the first 4 bits.