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

XOR function in REXX

145 views
Skip to first unread message

Roger Bruce

unread,
Apr 30, 2002, 8:38:14 PM4/30/02
to
Does anyone know how we can do an XOR function within rexx, if the
function itself isnt supported by your rexx implementation? We have a
requirement to XOR a hex number to ascertain a device address so we
can a) work out where the message came from, and b) possibly take
recovery action by issuing a hex command back to it.

Mark Yudkin

unread,
May 1, 2002, 3:13:28 AM5/1/02
to
xor(a,b) = and(or(a,b),not(and(a,b)))
"and" is written BITAND, "or" is written BITOR in REXX.
For "not", consider that not(a) = xor(a,true) and solve the equations!

"Roger Bruce" <roger...@bendigobank.com.au> wrote in message
news:dff1bf2b.02043...@posting.google.com...

Shmuel (Seymour J.) Metz

unread,
May 1, 2002, 10:40:41 AM5/1/02
to
In <dff1bf2b.02043...@posting.google.com>, on 04/30/2002

at 05:38 PM, roger...@bendigobank.com.au (Roger Bruce) said:

>Does anyone know how we can do an XOR function within rexx, if the
>function itself isnt supported by your rexx implementation?

Lot's of ways. The easiest way is probably Mark's suggestion to use
BITAND and BITOR. Alternatively, you could use c2b, add the binary,
translate "012" to "010" and use b2c, but that's the long way around.


--
Shmuel (Seymour J.) Metz, SysProg and JOAT
Atid/2, Team OS/2, Team PL/I

Any unsolicited commercial junk E-mail will be subject to legal
action. I reserve the right to publicly post or ridicule any
abusive E-mail.

I mangled my E-mail address to foil automated spammers; reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spam...@library.lspace.org

Ian Collier

unread,
May 8, 2002, 11:01:28 AM5/8/02
to
[See the bottom paragraph first...]

According to Mark Yudkin in a posting to comp.lang.rexx:


>xor(a,b) = and(or(a,b),not(and(a,b)))
>"and" is written BITAND, "or" is written BITOR in REXX.
>For "not", consider that not(a) = xor(a,true) and solve the equations!

I don't think those equations are soluble...

The closest we might get is: not(a) = d2c(true - c2d(a))
(where true = x2d(copies('FF', length(a))) or something like that).
But that's rather ugly and one might rather end up with Mr Metz's
suggestion:

bitxor: procedure
parse arg a,b
abits = x2b(c2x(a))
bbits = x2b(c2x(b))
numeric digits max(length(abits),length(bbits))
axbbits = translate(abits+bbits,0,2)
return x2c(b2x(axbbits))

However, I note that BITXOR() is listed as a built-in function in the
Rexx Reference Summary Handbook (c.1994) so I'm not sure what all this
fuss is about. ;-)

(Also, Rexx has a "logical xor" operator, namely: &&).
--
---- Ian Collier : i...@comlab.ox.ac.uk : WWW page (including REXX section):
------ http://users.comlab.ox.ac.uk/ian.collier/imc.shtml

New to this group? Answers to frequently-asked questions can be had from
http://rexx.hursley.ibm.com/rexx/ .

Roger Bruce

unread,
May 9, 2002, 12:27:37 AM5/9/02
to
ok, now I'm really confused..... LOL. So here is what we are trying
to do, straight from the CEMS100 protocol book....

CEMS100, btw, is the protocol use by Lieberts Air Handlers to
communicate with one another, and its all pretty much 'Hex speak'.

I'll try and do this without breaching the licence agreement on this
document.

Control Functions - a 5 byte message sent to the controller
Byte 1 - (Unit Number - 1) XOR f0h
eg f0h = unit1, f1h - unit 2 etc down to C2h = unit 51 etc onto 92h =
unit 99
Byte 2 - control request 11h
Byte 3 - Number of bytes to follow in this message (02h in this case)
Byte 4 - Control funtion Number 00h - 06h (wont say what they are)
Byte 5 - Checksum - the least significant byte of the binary sum of
bytes 1 to 4

There example is in basic, and noone I know has a memory that goes
back that far... But here it is anyway.

PRINT #1, CHR$ ((UNITNO-1)XOR 240); CHR$(17: CHR$(@); CHR$(TEMP);
CHKSUM = ((UNITNO-1)XOR 240) +17 +2 +TEMP
PRINT #1, CHR$(255 AND CHKSUM);

UNITNO is the unit number polled and TEMP is the control function
number.

How the heck do you do that in REXX?

Ian Collier

unread,
May 9, 2002, 6:51:14 AM5/9/02
to
Probably Roger Bruce typed into a real computer:

>PRINT #1, CHR$ ((UNITNO-1)XOR 240); CHR$(17: CHR$(@); CHR$(TEMP);
>CHKSUM = ((UNITNO-1)XOR 240) +17 +2 +TEMP
>PRINT #1, CHR$(255 AND CHKSUM);

>How the heck do you do that in REXX?

unitbyte = bitxor(d2c(unitno-1,1),'f0'x)
call charout , unitbyte || '1102'x || d2c(temp,1)
chksum = c2d(unitbyte) + 17 + 2 + temp
call charout , d2c(chksum,1)

Roger Bruce

unread,
May 10, 2002, 12:11:14 AM5/10/02
to
OK, thanks guys. Lots of valuable input here, and I've finally got my
head wrapped around it.... LOL.....

Can anyone tell me what a good book is that goes into details on
'standard' functions available to REXX, like stream subcommands, OLE
stuff etc? I have the esteemed Mr Cowlishaw's Practical Approach to
programming : The REXX language, but it due to implementation
specific's, a lot of this stuff is missing. We are running, what CA
call 'ANSI REXX', which is a bit of a lie, because half the ansi
standard isnt included (!!) on an NT box.

Shmuel (Seymour J.) Metz

unread,
May 10, 2002, 12:54:04 PM5/10/02
to
In <dff1bf2b.02050...@posting.google.com>, on 05/09/2002

at 09:11 PM, roger...@bendigobank.com.au (Roger Bruce) said:

>Can anyone tell me what a good book is that goes into details on
>'standard' functions available to REXX, like stream subcommands, OLE
>stuff etc?

OLE isn't standard. For STREAM, see the ANSI standard. For OS/2 I use
Dick Goran's REXX Reference Summary Handbook, but, again, a lot of the
important material is not standard.

>CA
>a bit of a lie

Redundant. Is there any reason to not run Regina or OREXX?

Ian Collier

unread,
May 10, 2002, 8:05:48 PM5/10/02
to
Shmuel (Seymour J.) Metz <spam...@library.lspace.org.invalid> told
comp.lang.rexx:

> For STREAM, see the ANSI standard.

Unfortunately not. The standard just says that the third parameter of
STREAM(stream,"C",command) is passed to the configuration to perform
some action.

I would have liked to have seen some "recommendations" of standard
stream commands, but the committee felt that this couldn't be specified
because not all environments are guaranteed to have such concepts as
(for instance) opening or closing files.

0 new messages