Question

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.

Was it helpful?

Solution

Like this, for example:

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

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

qDebug() << hex << bar;

Output:

beef
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top