Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Pages: [1]   Go Down
Author Topic: Compound bitwise XOR fails silently  (Read 1192 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: 51
Posts: 1734
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: 139
Posts: 6835
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
Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Jump to: