If you will be doing many of these kinds of tests, you can create a simple proc to tell you if the bit is on:

BitOn:
   If Arg(2) > Length(Arg(1)) * 8 Then Return 9;

   tval = Overlay('1',X2B(C2X(Copies('00'x,Length(Arg(1))))),Arg(2),1);
   tval = X2C(B2X(tval));
Return C2X(BitAnd(Arg(1),tval)) > 0;

The first test will return a 9 if you make an error, like specify Bit 9 of a 1-byte field. Otherwise, it will return a 1 or 0 as True or False indicating the bit is on or not. Note that it will work on multi-byte or single-byte values.

Examples:
If BitOn("AC",15) Then Say "It is on"    ---> RC (1): It is on
If BitOn("ABC",26) Then Say "It is on"  ---> RC (9): null
If BitOn("A",4) Then Say "It is on"        ---> RC (0): null


Thank you and best regards,
Billy Ashton

------ Original Message ------
From "Billy Ashton" <[email protected]>
To "IBM Mainframe Discussion List" <[email protected]>
Date 8/2/2022 8:40:49 AM
Subject Re: REXX Testing a bit?

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