Problem with Serial.print formatting

I have written a bit of diagnostic code to check out some added hardware to my Arduino Uno. Having written some random data to the added hardware (memory), I read it back and compare it against what was written. However, the serial monitor "appears" to be adding a byte of FF for negative hex numbers. Here is a code snippet- Serial.print("Data compare error at location "); Serial.print(j*512+i,DEC); Serial.print(" Read data = "); sprintf(chMsg,"%02X",chDataR); Serial.print(chMsg); Serial.print("\t");

Serial.print(" Write data = "); sprintf(chMsg,"%02X",chDataW); Serial.print(chMsg); Serial.print(" \n");

and here is a bit of serial monitor output to show the problem (lines 6 and 7):-

------- End of block 44 --------- Time for 512 byte block = 6816 microseconds. (13 uSecs per byte.) ------- End of block 45 --------- Time for 512 byte block = 6816 microseconds. (13 uSecs per byte.) Data compare error at location 23890 Read data = 0A Write data = 45 Data compare error at location 23891 Read data = FFA1 Write data = 50 Data compare error at location 23892 Read data = 3E Write data = FF9F .....

Any ideas about why the serial monitor is introducing this "sign extension" ?? Many thanks !

Any ideas about why the serial monitor is introducing this "sign extension" ??

Looks like you hit the nail on the head.

Please don't post snippets, and when you post code, please use code tags.

Looks like you hit the nail on the head.

So what if I don't want sign extension ...... ?

If you don't want sign extension, don't use signed datatypes

AWOL: If you don't want sign extension, don't use signed datatypes

Ahhhh ! Had forgotten that char defaulted to signed ! (Distracted by the hex representation) All fixed ! Ta !