Go Down

Topic: Compound bitwise XOR fails silently (Read 1 time) previous topic - next topic

Sketch:
===
void setup()
{
Serial.begin(9600);
byte x=0;
Serial.println("before:");
Serial.print(x);
Serial.println();
x^=0;
Serial.println("after:");
Serial.print(x);
Serial.println();
}
void loop()
{
}
===

Output:
===
before:
0
after:
0
===

el_supremo

What is wrong with that, apart from the fact that you don't know How to post code properly

Pete

westfw

Code: [Select]
x^=0;

a number xor'ed with 0 is just the number.
a number xor'ed with all 1s is the bitwise inversion of the number.
a number xor'ed with itself is always 0.


Go Up