Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bitwise comparision of bin fixed?

39 views
Skip to first unread message

johann woeckinger

unread,
May 23, 2023, 2:14:05 AM5/23/23
to
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

JW149

unread,
May 23, 2023, 6:00:10 PM5/23/23
to
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.


John W Kennedy

unread,
May 23, 2023, 8:16:15 PM5/23/23
to
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!

Peter Flass

unread,
May 23, 2023, 9:29:55 PM5/23/23
to
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

johann woeckinger

unread,
May 24, 2023, 10:35:14 AM5/24/23
to
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.
0 new messages