Closed
Description
It would be useful to include an example of comparison code for byte operations to the Bitshift reference page as it is mostly used for serial conversion, but it has no examples of its use.
This example below can be used to print out the value of a received byte to the serial monitor, using the Leftshift operator to move along the byte from bottom(LSB) to top (MSB), and print out its Binary value.
See following code:-
// Prints out Binary value (1 or 0) of byte
void printOut1(int c){
int bits;
for (bits = 7; bits >-1; bits--)
{
// Compare bits 7-0 in byte
if (c & (1 << bits)){
Serial.print ("1");
}
else
{
Serial.print ("0");
}
//next bit
}
// end of function
}