If the bit L18M1_STAT.03 has a value of 1, the the expression (L18M1_STAT AND 8) should have a value of 8. Since the multiplier of bit .03 is 16 in the original expression, multiplying (L18M1_STAT AND 8) (=> 8 or 0) by 2 gives the same result (i.e. 2*8 => 16 or 2*0 => 0).
TL;DR
The "AND 8" performs an
bitwise masking of the
bits in the
integer L19M1_STAT.
The
integer value "8" has bit 03 set (=1); all other bits 00-02, 04-07 are cleared (=0).
So when when we do a bitwise
integer AND of the eight
bits in L18M1_STAT with the
integer mask with a value of 8, each
bit of
integer LM18M1_STAT is logically ANDed with the corresponding
bit of the
integer value 8:
Code:
[U]Bit# => 7 6 5 4 3 2 1 0[/U]
LM18M1_STAT x x x x [B][COLOR=#ff0000][I]?[/I][/COLOR][/B] x x x
|
AND
|
v
Mask=8 0 0 0 0 [B][COLOR=#ff0000][I]1[/I][/COLOR][/B] 0 0 0
|
=
|
v
Result 0 0 0 0 [B][COLOR=#ff0000][I]?[/I][/COLOR][/B] 00 0
The result value will either be the
integer value 8 if
? is 1, or will be the
integer value 0 if
? is 0.
"x" means we don't care if a bit is 0 or 1, because those bits are always masked out to 0 in the result i.e. their corresponding bits in the ANDed result will be 0 because their corresponding bits in the mask are 0.
In the original formula, that bit L19M1_STAT.03 was used in a expression as
+ (L18M1_STAT.03 * 16), so if the
bit 03 is 1 or 0, then the
integer value added to the sum was 16 or 0, respectively.
So when using my ANDed expression, if the
integer result of
(L18M1_STAT AND 8) has a value of 8 or 0, then multiplying it by 2, via the expression
+ ((L18M1_STAT AND 8) * 2), adds an
integer value of either 16 or 0, respectively, to the sum, just like the original
(L18M1_STAT.03 * 16) expression.