例子:
float ieee754_to_float(const QByteArray &data ) { quint32 hexVal = quint32((quint8(data.at(0)) << 24) | (quint8(data.at(1)) << 16) | (quint8(data.at(2)) << 8) | (quint8(data.at(3)) << 0)); const float *fval= reinterpret_cast<const float *>(&hexVal ); return *fval; }
QByteArray data=“\x45\x6e\xdc\x3f”;
转换结果为:3821.765