Strange serial output

I am reading serial data coming from a series one xbee in API mode.

The data should read like this:
131 4 210 …and the rest makes sense so I will not bore you with it

OF is reading it as
-125 4 -46 …

why is it trying to make the number out of 256 and not 255?

it shouldn’t be like that, the readBytes method gets an unsigned char array as buffer so it doesn’t allow negative values. Perhaps you are printing them as char?

I was confused too.
I used a for loop to do printf(%i, value[i])
I am very new to C++ does the print a char or unsigned char?
The array is an unsigned char.
If it prints char how do I print the unsigned char? (just to check the data)

try with %u instead of %i

changed it to %u

now -125 came out as 4294967171
and -46 as 4294967250

No idea on that one.
At least -125 made sense to me 255-125 = 131

Running this code:

	printf("%i\n", (char) 131);  
	printf("%u\n", (char) 131);  
	printf("%i\n", (unsigned char) 131);  
	printf("%u\n", (unsigned char) 131);  

I get this:


So try just try re-casting your data as an unsigned char.

Also, a reference on printf.

Also, 4294967171 = 11111111111111111111111110000011, and 131 = 10000011.