I'm afraid that won't work because the first \x00 will be interpreted as the zero byte which terminates all C strings. I haven't tried it either, but I'm sure that only
If you want to condense your code so that all the hex printing happens on one line, you might try writing a short helper function to print arrays of values, per this example:
// This function prints "siz" HEX values from the "buf" array
void PrintHexBuffer(unsigned char *buf, size_t siz)
{
for (size_t i=0; i<siz; ++i)
Serial.println(buf[i], HEX);
}
void setup()
{
Serial.begin(9600);
unsigned char hex_buf[] = {0x00, 0x13, 0x2F, 0xFF, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
PrintHexBuffer(hex_buf, sizeof(hex_buf));
}
void loop()
{
}
I'm afraid that won't work because the first \x00 will be interpreted as the zero byte which terminates all C strings.
Ahh, good point.
So, I guess another approach would be to create a function similar to the one you showed and use the string with embedded \x00 but manually specify the string length--which is obviously a potential source of strange errors.
So, I guess another approach would be to create a function similar to the one you showed and use the string with embedded \x00 but manually specify the string length--which is obviously a potential source of strange errors.
Yeah, I think that would work, but as you point out, strings with embedded '\x00' bytes have the potential to be confusing and a little risky. Since their only advantage over unsigned char arrays is the (very slightly) condensed string syntax, I think I might still recommend arrays in this case.