I'm reading an output signal consiting of 3 (L,M,H) bytes (3x 8 bits) from a sensor.
This output signal however does not always need to be represented by 8 bits.
ex 010101 = 00010101
I would like to force the variable to consist of 8 bits no matter the size of the input number. All input bytes should be represented with an 8-bit length.
This is what my code looks like:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
byte L = 00000000;
byte M = 00000000;
byte H = 00000000;
}
void loop() {
// put your main code here, to run repeatedly:
while (Serial.available()) {
byte L = Serial.read();
byte M = Serial.read();
byte H = Serial.read();
Serial.println(L, BIN);
Serial.println(M, BIN);
Serial.println(H, BIN);
}
}