Pregunta

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.

¿Fue útil?

Solución

Like this, for example:

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

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

qDebug() << hex << bar;

Output:

beef
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top