PDA

View Full Version : Reading a decimal value stored in char



Miss Engineer
27th May 2014, 14:46
I have the following QByteArray
10384
For Message[3] I want to get the decimal value 201 and not -51. How do I do that? And where did this -51 come from?

anda_skoa
27th May 2014, 17:45
The byte can be interpreted as either an 8 bit unsigned/positive number or a 7bit signed number.

-55 is the two complement of 201 (255 - 201 + 1)

If you assign the value to a uchar then its value will be 201 since this removes the ambiguity.

Cheers,
_

Miss Engineer
28th May 2014, 01:23
It worked!
I have been working on a project using C++ and QT, both of which I've never used before.. When I'm really stuck, I know this forum will be my rescue! Thanks from the heart!


The byte can be interpreted as either an 8 bit unsigned/positive number or a 7bit signed number.

-55 is the two complement of 201 (255 - 201 + 1)

If you assign the value to a uchar then its value will be 201 since this removes the ambiguity.

Cheers,
_