Thus, you can view one operand of the bitwise-and operation as a mask: The bits set to 1 in the mask pass along the bits set to 1 in the other operand, whereas the bits set to 0 in the mask filter outor mask offany corresponding bits set to 1 in the other operand.
Accordingly, to determine whether, say, the bad-price bit in the status
variable is set, indicating that the analyze_trades
program has
encountered a 0 or negative price, you can mask off the other bits and
determine whether the on bit gets through. If the on bit does get through, the
result, viewed as an integer, is not zero, thus causing the statement
embedded in the following if statement to be executed.
*-- Mask v ------------- if (status & bad_price_bit) ...
Alternatively, you can use a mask with several bits set to test both bits that deal with the appearance of negative or zero numbers in the trade-describing file:
*-- Mask v ---------------------------- if (status & (bad_price_bit | bad_size_bit) ...