I usually am displaying something depending on the bit setting, so I wrote a small proc:

/*--------------------------------------------------------------------*
 * BITSW function: to test a bit for a value and return translation   *
 *--------------------------------------------------------------------*/
BitSw:
tr$ = Trace(o);                    ;

   test_str = Arg(1);
   test_bit = Arg(2);
   test_ret = Arg(3);

   Return Translate(Substr(x2b(test_str),test_bit,1),test_ret,"01");


You could use it like this:
mystring = BitSw(flag1,6,"NY")

This means:
Test the setting of bit 6 of the flag1 variable
Translate to the values I pass in (N, Y) from the bit value of 0, 1


Another simple way you could do it is to build your test mask (bit 6 on), and use this:
If C2X(Bitand(flag1,'00000100'b)) > 0 Then say "got it"

Thank you and best regards,
Billy Ashton

------ Original Message ------
From "Lionel B. Dyck" <[email protected]>
To [email protected]
Date 8/2/2022 7:50:10 AM
Subject REXX Testing a bit?

What is the best way to test if a bit is 1 or 0?



I'm doing this but was thinking there may/probably is a better way:



If substr(x2b(c2x(flag1)),6,1)  = 1 then say 'got  it'





Lionel B. Dyck <><

Website:  <https://www.lbdsoftware.com> https://www.lbdsoftware.com

Github:  <https://github.com/lbdyck> https://github.com/lbdyck



"Worry more about your character than your reputation. Character is what you
are, reputation merely what others think you are."   - - - John Wooden




----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to