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:
  1.  
  2.       // binary 10000000....0000, tests first (most significant) bit
  3.      D ACTIVE_CUST_MASK...
  4.      D                 C                   x'8000000000000000'
  5.       // binary 01000000....0000, test second bit
  6.      D PAYMENT_DUE_MASK...
  7.      D                 C                   x'4000000000000000'
  8.       // ...
  9.       // more masks here 
  10.       // ... 
  11.       
  12.       // binary 0000000000010000...0000, tests twelfth bit
  13.      D HAS_GOOD_GOLF_TOURNAMENT_MASK...
  14.      D                 C                   x'0010000000000000'
  15.       // ...
  16.       // many(!) more masks here 
  17.       // ... 
  18.       
  19.       // binary 0000000000010000...0000, tests sixty fourth bit 
  20.      D IS_STILL_WITH_ME_MASK...
  21.      D                 C                   x'0000000000000001'
  22.      
  23.       /free
  24.        if (%bitAnd(custFlags : ACTIVE_CUST_MASK) = ACTIVE_CUST_MASK);
  25.          // do active customer processing
  26.        elseif (%bitAnd(custFlags : PAYMENT_DUE_MASK) = PAYMENT_DUE_MASK);
  27.          // do payment due processing
  28.        
  29.        // and so on ...
  30.       
  31.        endif;
  32.       /end-free
© 2004-2019 by midrange.com generated in 0.008s valid xhtml & css