Hello,
i would like to output an int in 8bit format via the serial interface. Unfortunately, serial.putc(50) always prints 110010 instead of 00110010.
What do I have to do to get the number in 8bit format?
Thanks
Hello,
i would like to output an int in 8bit format via the serial interface. Unfortunately, serial.putc(50) always prints 110010 instead of 00110010.
What do I have to do to get the number in 8bit format?
Thanks
Ahoj,
I do not know how you check that, but maybe it can be by a setting of how you print bits of byte and the first zeros are automatically ignored.
When I printed bits in the past, I used this
BR, Jan
I like this answer from @JohnnyK’s link
const char *bit_rep[16] = {
[ 0] = "0000", [ 1] = "0001", [ 2] = "0010", [ 3] = "0011",
[ 4] = "0100", [ 5] = "0101", [ 6] = "0110", [ 7] = "0111",
[ 8] = "1000", [ 9] = "1001", [10] = "1010", [11] = "1011",
[12] = "1100", [13] = "1101", [14] = "1110", [15] = "1111",
};
void print_byte(uint8_t byte) {
printf("%s%s", bit_rep[byte >> 4], bit_rep[byte & 0x0F]);
}