The operation:
lo=(unsigned char)(u32r % 256);
lo=(unsigned char)(u32r % 256);
To copy to clipboard, switch view to plain text mode
is not doing what you want.
If u32r ist 257 for example, lo = 0 as a result in your code, which is false, it should be 1, or 0x01.
You also have other principal mistakes such as:
you are using a 32 bit vars, but only test their lower 8 and 16 bits.
It is possible that in you example the values really didn't go above 0xFFFF, but if they will, your code wont work even if correct hi/low dissection of the lower 8 and 16 bits.
Try the following:
//This code will only disect 16 bit values, for 32 values you will have to change the code in a similar way
for(unsigned short i=0; i<dock->tableWidget->rowCount(); i++){
unsigned short u16r=dock->tableWidget->item(i,2)->text().toUInt(&br);
qDebug()<<"["<<u16r<<"]";
if(!br)return;
hi=(unsigned char)(u16r>>8);
lo=(unsigned char)(u16r);
...
}
//This code will only disect 16 bit values, for 32 values you will have to change the code in a similar way
for(unsigned short i=0; i<dock->tableWidget->rowCount(); i++){
unsigned short u16r=dock->tableWidget->item(i,2)->text().toUInt(&br);
qDebug()<<"["<<u16r<<"]";
if(!br)return;
hi=(unsigned char)(u16r>>8);
lo=(unsigned char)(u16r);
...
}
To copy to clipboard, switch view to plain text mode
Note I didn't test this code for compilation, typos might be present, its just pseudo code to explain the concept, yet the code might compile ok.
Bookmarks