Smosia
23rd March 2014, 18:38
Hello.
Can you help me. I tried many methods to do that, but i didn't find solution.
I have 2 bytes of raw data (like that "45 FE"), stored in QByteArray (char 45, char FE). I want to convert them to qint16 (to decimal).
I have working solution (it's crazy:) ).
QByteArray buffer1;
qFromLittleEndian<qint16>((qint16)(buffer1.mid(i,1).at(0)))*256 + qFromLittleEndian<quint16>((const uchar *)buffer1.mid(i+1,1).constData());
Algoritm:
For numers > 0
converted first byte to signed qint16 * 256 + converted second byte to unsigned quint16.
For numbers < 0:
converted first byte to signed qint16 * 256 - converted second byte to unsigned quint16
256 = 100 in hex.
Could you recommend me right algorithm :) i think my algorithm is quite sophisticated :)
Can you help me. I tried many methods to do that, but i didn't find solution.
I have 2 bytes of raw data (like that "45 FE"), stored in QByteArray (char 45, char FE). I want to convert them to qint16 (to decimal).
I have working solution (it's crazy:) ).
QByteArray buffer1;
qFromLittleEndian<qint16>((qint16)(buffer1.mid(i,1).at(0)))*256 + qFromLittleEndian<quint16>((const uchar *)buffer1.mid(i+1,1).constData());
Algoritm:
For numers > 0
converted first byte to signed qint16 * 256 + converted second byte to unsigned quint16.
For numbers < 0:
converted first byte to signed qint16 * 256 - converted second byte to unsigned quint16
256 = 100 in hex.
Could you recommend me right algorithm :) i think my algorithm is quite sophisticated :)