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

BITAND, BITOR, BITXOR functions?

206 views
Skip to first unread message

John

unread,
Feb 15, 2006, 10:24:43 PM2/15/06
to
Has anyone ever used the BITAND, BITOR or BITXOR functions?

I'm curious as to what they do, but the doc examples are pretty sparse and I
can't extrapolate any possible usages out of them.

Does anyone have any ideas as to what sort of purpose they could be used
for? Why would someone need them?

I'm not really looking for code, but if anyone has any samples, that could
be helpful in figuring out what I could use them for myself, as they are one
of the few REXX functions that I can't think of any way to apply to a
practical problem.

Thanks!


Sahananda - Jon

unread,
Feb 16, 2006, 1:18:06 AM2/16/06
to

Well I was going to reply 'take a look at the ConnectResize example in
the OODialog manual' but I looked and to my surprise the function used
is binaryand not BITAND. That's funny I thought, must be a typo, then
I looked at the code I had used and that includes the 'binaryand'
function and it interprets fine. I thought it must be an oodialog
function, but no. I wonder what is going on?

Anyway, back to the topic, in the days of DOS, trying to squeeze as
much into my memory as possible I had an application that stored 8
attributes of items in a single byte (I had thousands of these items).
It is not significant in these examples that data.flag is a stem
variable - I had a routine that parsed my data out into a stem. Here
are the functions I used to manage them:

/*=== SetOn ===*/
SetOn:
Procedure expose data.flag
parse arg switch
data.flag=bitor(data.flag,switch)
return
/*=== IsOn ===*/
IsOn:
procedure expose data.flag
parse arg test
return bitand(data.flag,test)==test
/*=== SetOff ===*/
SetOff:
Procedure expose data.flag
parse arg switch
data.flag=bitand(data.flag,bitxor(switch,'ff'x))
return

and I used them like this:

parse value '8040201008040201'x with, /* Masks for
flag */
PriceChgFlag 2, /* price has changed */
LiveChangeFlag +1, /* SPin this session */
BestSellerFlag +1, /* Item is a bestslr */
InSaleFlag +1, /* Item is in sale */
CustomerInsFlag +1, /* spin for item. */
BadHiliteFlag +1, /* spin has been reviewed */
InARangeFlag +1, /* This item is in a range*/
ParentItemFlag +1 . /* This item is a BOM parent*/

then I could access them like this:

if pos('BEST',special_ins)>0
then call setOn BestSellerFlag
else call SetOn CustomerInsFlag /*There are
special Ins*/

or

if isOn(InARangeFlag) then ...

hope that is helpful,

Jon

Sahananda - Jon

unread,
Feb 16, 2006, 1:37:26 AM2/16/06
to
Sorry, there is more. If you wanted to check if either of a couple of
flags was on you could do it thus:

IsOn(BitOr(CustomerInsFlag,BestSellerFlag))

Another bit of code I had cycled through four colours for departments
that were represented by a single Alphabet character, ie Dept A is red,
Dept B is blue, dept C is green, dept D is purple, Dept E starts again
as red and so on. I'm on an Ascii OS (it would be slightly different
for EBCDIC) so I used:

dept_col=(16*c2d(bitand('03'x,data.dept)))

Jon

Don Hills

unread,
Feb 16, 2006, 7:23:39 AM2/16/06
to
In article <fSIf.80232$tK4....@tornado.ohiordc.rr.com>,

"John" <add...@server.com> wrote:
>Has anyone ever used the BITAND, BITOR or BITXOR functions?

I use BITAND to mask off, extract or zero bits within a byte.
I've used it to write Base64 encode/decode routines and to parse files
that use bitwise flags, such as MP3 files.

For example, in an MP3 frame the channel mode value is stored in the high
two bits of frame header byte 4:

bits = bitand('C0'x,fhb4)
select;
when bits = '00'x then chmode = 'Stereo'
when bits = '40'x then chmode = 'Joint Stereo'
when bits = '80'x then chmode = 'Dual Channel'
when bits = 'C0'x then chmode = 'Mono'
end;

--
Don Hills (dmhills at attglobaldotnet) Wellington, New Zealand
"New interface closely resembles Presentation Manager,
preparing you for the wonders of OS/2!"
-- Advertisement on the box for Microsoft Windows 2.11 for 286

Lee Peedin

unread,
Feb 16, 2006, 8:39:00 AM2/16/06
to
On 15 Feb 2006 22:18:06 -0800, "Sahananda - Jon"
<saha...@wlbc.co.uk> wrote:

>Anyway, back to the topic, in the days of DOS, trying to squeeze as

>much into my memory as possible ....

And Windows still does something similiar in regards to file
attributes. Here's some code that uses "bitand". I'm sure it will
linewrap very badly. If you can't reformat it, let me know and I'll
place it on line for download.

Lee

/* get_fileattr.rex */

/*
January 13, 2006
Lee Peedin - David Ruggles - Safe Data, Inc.
SysFileTree can not retrieve extended (high) attributes on Windows
*/
call SysCls
numeric digits 12


readonly = '1'~right(12, 0)
hidden = '10'~right(12, 0)
system = '100'~right(12, 0)
folder = '10000'~right(12, 0)
archive = '100000'~right(12, 0)
link = '1000000'~right(12, 0)
compressed = '100000000000'

objfso = .oleObject~New('Scripting.FileSystemObject')


-- Change the following line to be the file you wish to obtain
attributes on
target = 'c:\autoexec.bat'
call GetAttributes 'f',target
say

-- Change the following line to be the folder you wish to obtain
attributes on
target = 'c:\program files'
call GetAttributes 'd',target
say

-- Change the following line to be the file you wish to obtain
attributes on
target = 'c:\program files\oorexx\rexx.exe'
call GetAttributes 'f',target
say

exit

GetAttributes:
parse arg targettype, targetname

select
when targettype~translate = 'F' then
do
objfile = objfso~getfile(targetname)
call SysFileTree targetname, m., 'f', '*****'
end
when targettype~translate = 'D' then
do
objfile = objfso~getfolder(targetname)
call SysFileTree targetname, m., 'd', '*****'
end
otherwise
do
say 'Invalid Target Type'
return
end
end
attr = objfile~attributes()~d2x()~x2b()~right(12,0)
--say attr
if attr = 0 then say targetname '> No
Attributes Set' m.1~substr(31,5)
if attr~bitand(system) = system then say targetname '>
System ' m.1~substr(31,5)
if attr~bitand(readonly) = readonly then say targetname '>
Read Only ' m.1~substr(31,5)
if attr~bitand(hidden) = hidden then say targetname '>
Hidden ' m.1~substr(31,5)
if attr~bitand(folder) = folder then say targetname '>
Folder ' m.1~substr(31,5)
if attr~bitand(archive) = archive then say targetname '>
Archive ' m.1~substr(31,5)
if attr~bitand(link) = link then say targetname '>
Link ' m.1~substr(31,5)
if attr~bitand(compressed) = compressed then say targetname '>
Compressed ' m.1~substr(31,5)

return

Frank Clarke

unread,
Feb 16, 2006, 6:26:47 PM2/16/06
to
On Thu, 16 Feb 2006 03:24:43 GMT, "John" <add...@server.com> wrote:
<%fSIf.80232$tK4....@tornado.ohiordc.rr.com>

I use it for locating wildcard matches. Say you have a mask like "AB*D*F".
build two masks from this
lomask = Translate(mask,'00'x,'*')
himask = Translate(mask,'FF'x,'*')
maskl = Length(mask)
Now you can interrogate any string to see if it's a match:
if BITAND( Left(string,maskl),himask ) =
BITOR( Left(string,maskl),lomask) then match = true


(change Arabic number to Roman numeral to email)

Don Hills

unread,
Feb 17, 2006, 12:37:06 AM2/17/06
to
In article <s72av1t01ndukclal...@4ax.com>,

Frank Clarke <m5s...@tampabay.rr.com> wrote:
>
>I use it for locating wildcard matches.

Hey, that's clever. Consider it stolen. :-)

Frank Ellermann

unread,
Feb 17, 2006, 11:19:58 AM2/17/06
to
John wrote:

> Has anyone ever used the BITAND, BITOR or BITXOR functions?

<http://purl.net/xyzzy/src/md5.cmd> near the end. Bye, Frank

Frank Clarke

unread,
Feb 18, 2006, 12:32:49 AM2/18/06
to
On Fri, 17 Feb 2006 17:37:06 +1200, black.ho...@gmail.com (Don Hills)
wrote:
<CEW9Dtga...@attglobal.net>

>In article <s72av1t01ndukclal...@4ax.com>,
>Frank Clarke <m5s...@tampabay.rr.com> wrote:
>>
>>I use it for locating wildcard matches.
>
>Hey, that's clever. Consider it stolen. :-)

Not a problem. That's why God made programmers in pairs.

John

unread,
Feb 23, 2006, 8:05:32 PM2/23/06
to
I'd like to thank everyone that replied to this thread for their help with
examples of the BITxxx() functions. Because of the examples, I've been able
to cook up a use for it, even though it's sort of simple, but I'm just kinda
starting out with this function...

I created a routine that will convert the time to/from HH:MM:SS and SSSSS
(seconds) format and used BITOR to detect what format it was passed in (I
really wish this conversion was incorporated into the TIME() function just
like the DATE() function does, but anyway).

I've tested this out in ooRexx for Windows & Linux, as well as mainframe
TSO.

/* REXX to convert time from hh:mm:ss <> seconds */
/* pass time as arg in hh:mm:ss or seconds format */
/* example: seconds1AM = routinename('01:00:00') */
ARG time .

/* convert time based on passed time's format */
IF BITOR(time,' : : ') = time THEN DO
/* convert hh:mm:ss to seconds, pad w/ leading 0s */
PARSE VALUE time WITH hh':'mm':'ss
converted_time = RIGHT(((hh * 60 + mm) * 60) + ss,5,'0')
END
ELSE DO
/* convert seconds to hh:mm:ss */
hh = RIGHT(time % 3600,2,'0')
mm = RIGHT(time % 60 - hh * 60,2,'0')
ss = RIGHT(time - (hh * 3600 + mm * 60),2,'0')
converted_time = hh':'mm':'ss
END
RETURN converted_time /* send converted time back to caller */

0 new messages