I've been working trying to read some C code and I've found some operators that I don't know:
What's the use of &=
and |=
operators when used for microprocessors programming?
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It only takes a minute to sign up.
Sign up to join this communityI've been working trying to read some C code and I've found some operators that I don't know:
What's the use of &=
and |=
operators when used for microprocessors programming?
These statements are equivalent:
x = x & 0x01;
x &= 0x01;
It means to perform a bitwise operation with the values on the left and right-hand side, and then assign the result to the variable on the left, so a bit of a short form. If you're not familiar with bitwise operations, I suggest you start getting familiar with those first - the &
being a bitwise AND and the |
being a bitwise OR.
Hope that helps!
&=
is and equals
, |=
is or equals
. These perform bit-wise operations with the left hand and right hand arguments, and assign the result into the left hand side.
=
means is equal to
(that's what equals
means!). ==
means equals
, =
means assign ... to
.
\$\endgroup\$