• bitwise comparision of bin fixed?

    From johann woeckinger@21:1/5 to All on Mon May 22 23:14:04 2023
    hi,
    i somehow think there must be a way to do the following, but can't remember / figure out how (feel pretty stupid):
    assume i have an OPTIONS variable that can contain several TRUE/FALSE at once.

    dcl options bin fixed(31);
    dcl 1 options_c,
    2 bold bin fixed(31) value(1),
    2 italic bin fixed(31) value(2),
    3 underscore bin fixed(31) value(4);
    options = bold+underscore;

    how do i - most smart - check for the single options?
    something like

    if options & options_c.bold then ...

    thanks in advance,
    br johann

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JW149@21:1/5 to johann woeckinger on Tue May 23 22:58:46 2023
    On 23/05/2023 07:14, johann woeckinger wrote:
    hi,
    i somehow think there must be a way to do the following, but can't remember / figure out how (feel pretty stupid):
    assume i have an OPTIONS variable that can contain several TRUE/FALSE at once.

    dcl options bin fixed(31);
    dcl 1 options_c,
    2 bold bin fixed(31) value(1),
    2 italic bin fixed(31) value(2),
    3 underscore bin fixed(31) value(4);
    options = bold+underscore;

    how do i - most smart - check for the single options?
    something like

    if options & options_c.bold then ...

    thanks in advance,
    br johann


    How about

    TSTtest206: PROCEDURE options(main);

    n1=15; n2=2;
    put skip edit("n1=",n1,"(",unspec(n1),")")(a,f(5),a,b(8),a);
    put skip edit("n2=",n2,"(",unspec(n2),")")(a,f(5),a,b(8),a);
    result=(unspec(n1) & unspec(n2));
    put skip edit(result,n3)(b(8),x(1),f(5));

    n1=13; n2=2;
    put skip edit("n1=",n1,"(",unspec(n1),")")(a,f(5),a,b(8),a);
    put skip edit("n2=",n2,"(",unspec(n2),")")(a,f(5),a,b(8),a);
    result=(unspec(n1) & unspec(n2));
    put skip edit(result,n3)(b(8),x(1),f(5));
    return;

    Dcl(n1,n2,n3) fixed bin(31),
    result bit(32) based(addr(n3));
    end TSTtest206;

    n1= 15(00001111) OPTIONS
    n2= 2(00000010) ITALICS only
    00000010 2 AND operation says ITALICS in effect

    n1= 13(00001101) OPTIONS
    n2= 2(00000010) ITALICS only
    00000000 0 AND operation says ITALICS not in effect

    Using n3 and result overlaid allows you to test ITALICS by the result
    2(on) 0(off)
    I could not see a builtin function the opposite of UNSPEC, hence my overlay.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John W Kennedy@21:1/5 to All on Tue May 23 20:15:12 2023
    On 5/23/23 5:58 PM, JW149 wrote:
    On 23/05/2023 07:14, johann woeckinger wrote:
    hi,
    i somehow think there must be a way to do the following, but can't
    remember / figure out how (feel pretty stupid):
    assume i have an OPTIONS variable that can contain several TRUE/FALSE
    at once.

    dcl options bin fixed(31);
    dcl 1 options_c,
        2 bold bin fixed(31) value(1),
        2 italic bin fixed(31) value(2),
        3 underscore bin fixed(31) value(4);
    options = bold+underscore;

    how do i - most smart - check for the single options?
    something like

    if options & options_c.bold then ...

    thanks in advance,
    br johann


     How about

     TSTtest206: PROCEDURE  options(main);

     n1=15; n2=2;
     put skip edit("n1=",n1,"(",unspec(n1),")")(a,f(5),a,b(8),a);
     put skip edit("n2=",n2,"(",unspec(n2),")")(a,f(5),a,b(8),a);
     result=(unspec(n1) & unspec(n2));
     put skip edit(result,n3)(b(8),x(1),f(5));

     n1=13; n2=2;
     put skip edit("n1=",n1,"(",unspec(n1),")")(a,f(5),a,b(8),a);
     put skip edit("n2=",n2,"(",unspec(n2),")")(a,f(5),a,b(8),a);
     result=(unspec(n1) & unspec(n2));
     put skip edit(result,n3)(b(8),x(1),f(5));
     return;

     Dcl(n1,n2,n3)              fixed bin(31),
         result                 bit(32) based(addr(n3));
     end TSTtest206;

    n1=   15(00001111)         OPTIONS
    n2=    2(00000010)           ITALICS only
    00000010     2             AND operation says ITALICS in effect

    n1=   13(00001101)         OPTIONS
    n2=    2(00000010)         ITALICS only
    00000000     0             AND operation says ITALICS not in effect

    Using n3 and result overlaid allows you to test ITALICS by the result
    2(on) 0(off)
    I could not see a builtin function the opposite of UNSPEC, hence my
    overlay.

    UNSPEC, like SUBSTR, can be used backwards, as a pseudovariable.


    DECLARE nullchar CHAR; UNSPEC(nullchar) = '00000000'B;
    --
    John W. Kennedy
    Algernon Burbage, Lord Roderick, Father Martin, Bishop Baldwin,
    King Pellinore, Captain Bailey, Merlin -- A Kingdom for a Stage!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter Flass@21:1/5 to johann woeckinger on Tue May 23 18:28:14 2023
    johann woeckinger <woecki@gmail.com> wrote:
    hi,
    i somehow think there must be a way to do the following, but can't
    remember / figure out how (feel pretty stupid):
    assume i have an OPTIONS variable that can contain several TRUE/FALSE at once.

    dcl options bin fixed(31);
    dcl 1 options_c,
    2 bold bin fixed(31) value(1),
    2 italic bin fixed(31) value(2),
    3 underscore bin fixed(31) value(4);
    options = bold+underscore;

    how do i - most smart - check for the single options?
    something like

    if options & options_c.bold then ...

    thanks in advance,
    br johann



    You don’t mention what compiler. IBM Enterprise compilers have IAND, IOR , etc builtins. Personally I’d use bit variables, which I think would be clearer:
    dcl options bit(32);
    dcl bold bit(32) value (‘00000001’bx);
    dcl italic bit(32) value(‘00000002’bx);
    dcl underscore bit(32) value(‘00000004’bx):


    Then you could code exactly what you want (I think):
    options = bold | underscore;
    if options & bold then ...
    [I would do options & bold != ‘00000000’bx where ! is not, I use this a lot.]
    To test for a one of several use
    if (options & (bold | underscore) ) != ‘00000000’bx
    To test for a specific combination use:
    if (options & (bold | underscore)) = bold | underscore

    This should be pretty efficient, at least it is in Iron Spring PL/I.

    --
    Pete

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From johann woeckinger@21:1/5 to johann woeckinger on Wed May 24 07:35:13 2023
    johann woeckinger schrieb am Dienstag, 23. Mai 2023 um 08:14:05 UTC+2:
    hi,
    i somehow think there must be a way to do the following, but can't remember / figure out how (feel pretty stupid):
    assume i have an OPTIONS variable that can contain several TRUE/FALSE at once.

    dcl options bin fixed(31);
    dcl 1 options_c,
    2 bold bin fixed(31) value(1),
    2 italic bin fixed(31) value(2),
    3 underscore bin fixed(31) value(4);
    options = bold+underscore;

    how do i - most smart - check for the single options?
    something like

    if options & options_c.bold then ...

    thanks in advance,
    br johann

    Many, many thanks for the various suggestions.
    Currently i think the solution i like most ist IAND.

    if iand(options, options_c.bold) <> 0 then ...

    I'm considering putting it into a Preproc macro, something like
    if BITWISE_AND(options, options_c.bold) then ...
    but thats personal taste.

    br Johann

    PS: sorry for not mentioning my compiler, its Enterprise PL/I on z/os
    PPS: i'm aware that i can implement something similar using bitarrays, but i like the readability of "options = bold + underscore", especially if i use setter method "set_options(bold + underscore)". But again: thats personal taste & depends on the
    situation.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)