Int shows higher value than expected

Hi People,

I have this odd situation and I cannot get my head around it.

I have an Integer, Which covers 2 bytes of data, Right?
I give that integer a Hex value of 2 bytes.
Why does the Serial print show 4 bytes, with 2 "empty" bytes beeing MSB?
That's it... Nothing more, nothing less, concerning this part of the code.

I give 0xCDEF, and I get FFFFCDEF
How is that possible?

Serial.println("Printed value:  ");
  int BoSE (0xCDEF);
  Serial.println (BoSE, HEX);

Serial.println() does a typecast to long and a sign extension. Try making the int unsigned and see what happens.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.