if (state & 1)
is same is if state is odd
.
return (stat == SOME_MACRO);
is same as
if (state == SOME_MACRO)
return true;
else
return false;
Explanation: The binary representation of any odd number would have a 1 at its last digit. For example,
3 = 11
5 = 101
7 = 111
If you already know what &
does, you will notice that when you perform n & 1
, all bits except the last one is set to zero, and the last bit remain unchanged. So n & 1
returns the last bit of n
, which is 1
if n
is odd, and 0
if n
is even.
And (state == SOME_MACRO)
will evaluate to true
if the expression is True, and evaluate to false
if the expression is False. So it will return either true
or false
depending if state
is equal to SOME_MACRO
or not.