[Solved] How to supress leading zero trimming with serial.print(var, HEX);

PaulS:

so defining dataStream as a 6 char long array dataStream[6] should never changed from the default NULL to provide a properly null-terminated char array

That statement is going to write at least 6 characters to the array - the single character, two character or more, for the first value, two characters or more for the second value, and a terminating NULL.

Given that the value is a byte, there won't be more than 2 characters per value, but the assumption that the default value in the 6th position in the array (a NULL) won't be overwritten is incorrect. sprintf() DOES NULL terminate the array.

So, because the value being fed to the template %02X is a byte, why can't I expect that in all cases the result will always be two characters? I'm expecting that so I would have 1 + 2 + 2 = 5 characters as a result from sprintf(). How would that ever overwrite the 6th character of the array? I suppose I could follow the sprintf() with dataStream[5] = 0x0;, but why would that ever be necessary? I'm just not seeing it.

Edit: Corrected the off-by-one error in the array index. ::face-palm::