Hi,

I have a QByteArray with 4 bytes in that I want to put in an unsigned int with C, sounds simple but ive spent hours messing around and it wont work

Heres an example of what im trying to do, say i have 4 hex bytes 0xFFAD32FF in a QByteArray as data[0] = 0xFF data[1] = 0xAD data[2] = 0x32 data[3] =0xFF and this wants to go into an uint to give the equivalent decimal value of 4289540863.

Im using x86 hardware, so little endian is in use, so I think im correct in saying i have to put the bytes from the array in reverse order? so the unsigned int will look like 0xFF 0x32 0xAD 0xFF in memory is that correct?

Heres my code:
Qt Code:
  1. QByteArray input;
  2. // test number
  3. input[0] = 0xFF
  4. input[1] = 0xAD
  5. input[2] = 0x32
  6. input[3] = 0xFF
  7.  
  8. // Convert to uint
  9. result = input[3];
  10. result = result << 8 | input[2];
  11. result = result << 8 | input[1];
  12. result = result << 8 | input[0];
To copy to clipboard, switch view to plain text mode 

This gives me a result of 4294967295 instead of 4289540863.

Please can someone point me in the right direction, ive spent a crazy amount of time trying to fix it