Frage

I am trying to take 2. and 3. index content values from a char[3] array. How can I take these two bytes to copy, equaling to quint16 variable.

War es hilfreich?

Lösung

Like this, for example:

char foo[3] = { 0x99, 0xEF, 0xBE };

quint16 bar = (quint8)(foo[1]) + (((qint8)(foo[2]))<<8);

qDebug() << hex << bar;

Output:

beef
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top