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!
|
|
0
|
|
|
|
Reply
|
address (2)
|
2/16/2006 3:24:43 AM |
|
John wrote:
> 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!
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
|
|
0
|
|
|
|
Reply
|
Sahananda
|
2/16/2006 6:18:06 AM
|
|
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
|
|
0
|
|
|
|
Reply
|
Sahananda
|
2/16/2006 6:37:26 AM
|
|
In article <fSIf.80232$tK4.61479@tornado.ohiordc.rr.com>,
"John" <address@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
|
|
0
|
|
|
|
Reply
|
black
|
2/16/2006 12:23:39 PM
|
|
On 15 Feb 2006 22:18:06 -0800, "Sahananda - Jon"
<sahananda@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
|
|
0
|
|
|
|
Reply
|
Lee
|
2/16/2006 1:39:00 PM
|
|
On Thu, 16 Feb 2006 03:24:43 GMT, "John" <address@server.com> wrote:
<%fSIf.80232$tK4.61479@tornado.ohiordc.rr.com>
>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.
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)
|
|
0
|
|
|
|
Reply
|
Frank
|
2/16/2006 11:26:47 PM
|
|
In article <s72av1t01ndukclalho1j07hc334ugim45@4ax.com>,
Frank Clarke <m5srexx@tampabay.rr.com> wrote:
>
>I use it for locating wildcard matches.
Hey, that's clever. Consider it stolen. :-)
--
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
|
|
0
|
|
|
|
Reply
|
black
|
2/17/2006 5:37:06 AM
|
|
John wrote:
> Has anyone ever used the BITAND, BITOR or BITXOR functions?
<http://purl.net/xyzzy/src/md5.cmd> near the end. Bye, Frank
|
|
0
|
|
|
|
Reply
|
Frank
|
2/17/2006 4:19:58 PM
|
|
On Fri, 17 Feb 2006 17:37:06 +1200, black.hole.4.spam@gmail.com (Don Hills)
wrote:
<CEW9DtgaXCMX092yn@attglobal.net>
>In article <s72av1t01ndukclalho1j07hc334ugim45@4ax.com>,
>Frank Clarke <m5srexx@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.
(change Arabic number to Roman numeral to email)
|
|
0
|
|
|
|
Reply
|
Frank
|
2/18/2006 5:32:49 AM
|
|
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
|
|
|
|
Reply
|
John
|
2/24/2006 1:05:32 AM
|
|
|
9 Replies
470 Views
(page loaded in 0.102 seconds)
Similiar Articles: The wonders of the glPolygonMode function - comp.graphics.api ...BITAND, BITOR, BITXOR functions? - comp.lang.rexx The wonders of the glPolygonMode function - comp.graphics.api ... BITAND, BITOR, BITXOR functions? - comp.lang.rexx ... Is there any clever way to encode the uuid string with base64 ...BITAND, BITOR, BITXOR functions? - comp.lang.rexx I've used it to write Base64 encode/decode routines and to ... the few REXX functions that I can't think of any way ... Help a twit with DB2 and SQL with REXX - comp.lang.rexxBITAND, BITOR, BITXOR functions? - comp.lang.rexx Help a twit with DB2 and SQL with REXX - comp.lang.rexx BITAND, BITOR, BITXOR functions? - comp.lang.rexx > of the few ... REXX Listcat example in TSO 3.4 option? - comp.lang.rexx ...BITAND, BITOR, BITXOR functions? - comp.lang.rexx REXX Listcat example in TSO 3.4 option? - comp.lang.rexx ... BITAND, BITOR, BITXOR functions? - comp.lang.rexx REXX ... Cant get "grant execute on procedure" to work. - comp.databases ...BITAND, BITOR, BITXOR functions? - comp.lang.rexx... but the doc examples are pretty sparse and I can't ... used to manage them: /*=== SetOn ===*/ SetOn: Procedure ... Bitwise operators - comp.lang.fortranBITAND, BITOR, BITXOR functions? - comp.lang.rexx Bitwise operators - comp.lang.fortran... rexx - comp.lang.rexx Bitwise operators - comp.lang.fortran > 1>Compiling with ... bit manipulation question - comp.lang.asm.x86BITAND, BITOR, BITXOR functions? - comp.lang.rexx... Post Question | Groups ... The bit manipulation funcitons; Function Description The bit in the twos complement ... Balloon numbers do not match BOM - comp.cad.solidworksBITAND, BITOR, BITXOR functions? - comp.lang.rexx I'm curious as to what they do, but the doc ... /* This item is a BOM parent*/ then I could ... BITOR( Left(string,maskl ... BITAND, BITANDNOT, BITOR, BITXOR, and BITNOT scalar functionsTable 1. The bit manipulation functions; Function Description A bit in the two's complement representation of the result is: BITAND: Performs a bitwise AND operation. DB2 10 - DB2 SQL - BITAND, BITANDNOT, BITOR, BITXOR, and BITNOTTable 1. The bit manipulation funcitons; Function Description The bit in the twos complement representation of the result; BITAND: Performs a bitwise AND operation. 7/23/2012 9:07:12 AM
|