I am working on my RS485 bustelegram and reserved 2 bytes as command word stored as short. To send the telegram as whole package 'transform' the short to fit into an char array.
Your signed integer values (char, short, int, long) get sign-extended when converted to a longer type.
Serial.print() prints all signed integers as 'long'. For DECimal it isn't a problem since all those sign-extended bits just show up as a minus-sign. For HEXadecimal and BINary the sign extension is sorely visible. I recommend casting your signed values to unsigned values of the same length:
This means that the process data only holds the value I intend?
short RECEIVE_COMMAND = 0xABCD;
and is only represented as per definition of the print method
'FFFFABCD'
Thanks for the clarification. Since my telegram has a fixed length and a short only has 2 bytes no additional bytes can be smuggled in. I just was not sure why I am seeing seemingly wrong data.
No, because Serial.print() doesn't put in the '0x' prefix and suppresses leading zeroes. An 'unsigned short' or 'uint16_t' containing 0xABCD would print out as ABCD. If it had the value 0x0123 it would print out as 123.