Pages: [1]   Go Down
Author Topic: Compound bitwise XOR fails silently  (Read 1052 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: 43
Posts: 1551
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

Where are the Nick Gammons of yesteryear?

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6634
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: