midrange.com code scratchpad |
Name:
Bitmask example
|
Scriptlanguage:
Plain Text
|
Tabwidth:
4
|
Date:
06/22/2009 04:21:12 pm
|
IP:
Logged
|
|
Description:
Using bitmasks to test customer flags
|
Code:
-
- // binary 10000000....0000, tests first (most significant) bit
- D ACTIVE_CUST_MASK...
- D C x'8000000000000000'
- // binary 01000000....0000, test second bit
- D PAYMENT_DUE_MASK...
- D C x'4000000000000000'
- // ...
- // more masks here
- // ...
-
- // binary 0000000000010000...0000, tests twelfth bit
- D HAS_GOOD_GOLF_TOURNAMENT_MASK...
- D C x'0010000000000000'
- // ...
- // many(!) more masks here
- // ...
-
- // binary 0000000000010000...0000, tests sixty fourth bit
- D IS_STILL_WITH_ME_MASK...
- D C x'0000000000000001'
-
- /free
- if (%bitAnd(custFlags : ACTIVE_CUST_MASK) = ACTIVE_CUST_MASK);
- // do active customer processing
- elseif (%bitAnd(custFlags : PAYMENT_DUE_MASK) = PAYMENT_DUE_MASK);
- // do payment due processing
-
- // and so on ...
-
- endif;
- /end-free
|
|
|