Pages

Tuesday, June 4, 2024

Toggle a bit in C using XOR

  


int number= 0b11001100;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
number ^= 1 << 2;
delay(100);
Serial.println(number,BIN);

}



since we count from zero the 3rd last bit will toggle









No comments:

Post a Comment

What is Imperialism?

Ans: Imperialism refers to the practice by which a powerful nation establishes political and economic control over another country. Britain ...