Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!van-bc!rsoft!mindlink!a665 From: a665@mindlink.UUCP (Anthon Pang) Newsgroups: comp.lang.modula2 Subject: Re: Bitwise EXOR Message-ID: <3356@mindlink.UUCP> Date: 29 Sep 90 03:37:26 GMT Organization: MIND LINK! - British Columbia, Canada Lines: 32 Herman.Stevens@p21701.f601.n292.z2.fidonet.org writes: > I am a beginner with Modula-II. I work on an Amiga with the M2Amiga > compiler. I fail to see how I can do a bitwise EXOR, something you > can easily write in C as : > > tmpbuf[i] = inbuf[i]^key[kp] > > Can someone help me on this ? I think the following work... For booleans: x := ( a OR b) AND (NOT (a AND b)); and for other stuff (using sufficient type transfer): TYPE longbs = SET OF [0..31]; (* LONG WORD BITSET *) PROCEDURE XOR ( x, y: longbs ) : longbs; CONST allset = longbs{0..31}; BEGIN RETURN (x + y) * (allset - (x * y)); END XOR; For the latter case, your example would translate (roughly) to: tmpbuf[i] := LONGCARD( XOR(longbs(inbuf[i]), longbs(key[kp]))); assuming tmpbuf is an ARRAY of LONGCARD. Change "LONGCARD" to "CARDINAL" and "31" to "15"...and it should work for word size (16 bit) values as well (ie on the Amiga).