From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,afb6e61f9b1678d1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-02 20:14:32 PST Path: archiver1.google.com!news2.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc01.POSTED!not-for-mail From: "Steve" Newsgroups: comp.lang.ada References: Subject: Re: Bitwise XOR? X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: NNTP-Posting-Host: 12.211.13.75 X-Complaints-To: abuse@comcast.net X-Trace: sccrnsc01 1065150871 12.211.13.75 (Fri, 03 Oct 2003 03:14:31 GMT) NNTP-Posting-Date: Fri, 03 Oct 2003 03:14:31 GMT Organization: Comcast Online Date: Fri, 03 Oct 2003 03:14:31 GMT Xref: archiver1.google.com comp.lang.ada:141 Date: 2003-10-03T03:14:31+00:00 List-Id: "Adrian Knoth" wrote in message news:slrnbnnohq.26h.adi@ppc201.mipool.uni-jena.de... > David N. Maez wrote: > > > x : integer; > > y : integer; > > x := x xor y; > > > What am I missing? > > There is no XOR defined for anything else than bits. You'll need > to mask the bits and recombine the result. > Not true. Ada 95 permits using XOR on modular types. If you want to XOR between integers, convert the integer to a modular type, do the XOR, then convert the result back. The following (tested) routine does exactly this. function "xor"(Left,Right : in Integer) return Integer is pragma inline("xor"); type Int_As_Mod is mod 2 ** Integer'size; function To_Mod is new Ada.Unchecked_Conversion( Integer, Int_As_Mod ); function To_Int is new Ada.Unchecked_Conversion( Int_As_Mod, Integer ); begin return To_Int( To_Mod(Left) XOR To_Mod(Right) ); end "xor"; Steve (The Duck) [excessively complicated untested example deleted] > -- > mail: adi@thur.de http://adi.thur.de PGP: v2-key via keyserver > > M�nner sind wie Jeans: blau und steif...