Pages: [1]   Go Down
Author Topic: Compound bitwise XOR fails silently  (Read 1158 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 4
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
===
Logged

Offline Offline
Edison Member
*
Karma: 49
Posts: 1670
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pete
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 137
Posts: 6788
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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.

Logged

Pages: [1]   Go Up
Jump to: