I’m not sure if you’re still asking a question?
It’s just that the code does not print leading zeroes, which for humans often have no meaning. Each byte is always 8 bits, so you’re really sending 11110001 00000000 11111011. And hexadecimal F1 0 FB is the same as F1 00 FB, or f1 00 fb, or f100fb, and so on.
To print the leading zeroes, see other examples, like:
for (int i = 0; i < size; i++) {
if (data[i] < 0x10) {
Serial.print(F("0"));
}
Serial.print(data[i], HEX);
}
For binary, where the number of leading zeroes could be as many as 7, that’s a bit more difficult in Arduino. Many people on the Arduino forums use the bitRead like you used elsewhere in your code already, like, untested:
for (int i = 0; i < size; i++) {
for (int bit = 7; bit >= 0; bit--) {
Serial.print(bitRead(data[i], bit));
}
Serial.print(" ");
}
Fun fact: for computer code, a leading zero often denotes an octal number, just like a leading 0x denotes it’s a value in hexadecimal notation. Like in, e.g., C, C++, Java and JavaScript, 10 (decimal) and 010 (octal) are not the same. But in funny JavaScript, 80 and 080 are the same, while 70 and 070 are not… ![]()