Go Down

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

t0mpr1c3

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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy