在QT我有一个qint64.是否有一种简单的方法将其分成大小为int8_t?
为清楚起见,如果我有一个
qint64 a = [11001000 00001111 11110000 ... 11001100]
Run Code Online (Sandbox Code Playgroud)
我想得到
int8_t a1=[11001000]
int8_t a2=[00001111]
int8_t a3=[11110000]
...
int8_t a8=[11001100]
Run Code Online (Sandbox Code Playgroud)
这比Ct更像是一个C/C++问题.但无论如何:
qint64 a = 56747234992934;
union {
qint64 i64;
int8_t i8[8];
} u = {a};
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
qDebug() << u.i8[0]; // MSB is the first byte on big endian machines
#else
qDebug() << u.i8[7]; // MSB is the last byte on little endian machines
#endif
Run Code Online (Sandbox Code Playgroud)
编辑:为避免凌乱的endian特定位置代码:
qint64 a = 56747234992934;
union {
qint64 i64;
int8_t i8[8];
} u = {qToBigEndian(a)};
qDebug() << u.i8[0]; // MSB is the first byte on big endian machines
Run Code Online (Sandbox Code Playgroud)
请注意,您需要包含qendian.h
此功能.