Thank you very much, now how can I make the comparison with the if function of the bit x?
int value = 100 ;
void setup() {
Serial.begin (115200);
}
void loop() {
if (value,bin bit 1== 1) { do something}; // how to spell correctly?
Serial.println (value,BIN);
}
Here's some ideas using bit shifting to get all 8 bits of the number printed, and then using bitRead() for the conditional testing.
void setup() {
Serial.begin(9600);
byte x = 47;
printBinary(x);
bitTest(x);
}
void loop() {
}
void printBinary(byte b) {
for (int i = 7; i >= 0; i-- )
{
Serial.print((b >> i) & 0X01);//shift and select first bit
}
Serial.println();
}
void bitTest(byte b) {
for (int i = 7; i >= 0; i-- )
{
Serial.print("Bit Number ");
Serial.print(i);
Serial.print (" is ");
Serial.println(bitRead(b, i));
if (bitRead(b, i) == 1)
Serial.println ("//code if match 1");
else
Serial.println ("//code if match 0");
Serial.println();
}
}