Your code will output nothing because it never puts anything in the result QByteArray (compare line 10 and 11). Even if it did your result would not be what you expect.
A QByteArray stores bytes, nothing else. As in my last post you want to look at the QVector or QList templates to store other types.
ByteArray ba; // an array of bytes (chars actually)
ba[0] = 0x1d;
ba[1] = 0x17;
ba[2] = 0x11;
ba[3] = 0x00;
QList<quint16> result; // A list of 16 bit unsigned integers
for (int i = 0; i < ba.size(); i+=2)
result.append(
(static_cast<unsigned char>(ba.at(i) << 5))
| static_cast<unsigned char>(ba.at(i+1))
);
}
ByteArray ba; // an array of bytes (chars actually)
ba[0] = 0x1d;
ba[1] = 0x17;
ba[2] = 0x11;
ba[3] = 0x00;
QList<quint16> result; // A list of 16 bit unsigned integers
for (int i = 0; i < ba.size(); i+=2)
result.append(
(static_cast<unsigned char>(ba.at(i) << 5))
| static_cast<unsigned char>(ba.at(i+1))
);
}
To copy to clipboard, switch view to plain text mode
You have to convert result to hex entry by entry, there is no toHex() to rely on. If you don't need the result retained in binary form (i.e. the result QList) then you can build the hex string as you go along. Conversion
Bookmarks