Reputation: 315
I need to send data over rs232,but I'm facing a problem.
When I send byte representing integer over 128, it looks like QByteArray changes the content I feed it:
uchar uc_array[]={0x41,0xAA}; //65 170
QByteArray qb_array = QByteArray();
qb_array.append(uc_array[0]);
qb_array.append(uc_array[1]);
cout<<(uint)qb_array[0]<<endl //65
cout<<(uint)qb_array[1]<<endl //4294967210
Why
cout<<(uint)qb_array[1]<<endl
doesn't print 170, but 4294967210 instead ?
Upvotes: 0
Views: 307
Reputation: 6526
Here is my explanation of why you print 4294967210 instead of 170, which is your original question:
qb_array[1]
returns a signed char
type with 0xAA valuesigned char
to uint
type:
int
type, keeping the sign: it becomes 0xFFFFFFAAUpvotes: 3