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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,afb6e61f9b1678d1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-03 03:31:35 PST Path: archiver1.google.com!news2.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!ucberkeley!news.tele.dk!news.tele.dk!small.news.tele.dk!news.agarik.com!news.agarik.com!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: "Beard, Frank Randolph CIV" Newsgroups: comp.lang.ada Subject: RE: Bitwise XOR? Date: Fri, 3 Oct 2003 06:28:15 -0400 Organization: Cuivre, Argent, Or Message-ID: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: melchior.cuivre.fr.eu.org 1065177023 11228 80.67.180.195 (3 Oct 2003 10:30:23 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Fri, 3 Oct 2003 10:30:23 +0000 (UTC) To: "Steve" , Return-Path: X-MimeOLE: Produced By Microsoft Exchange V6.0.6375.0 content-class: urn:content-classes:message X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Bitwise XOR? Thread-Index: AcOJXU30K3ounDxYTYqfY8DE6Y9NMgAOst2w X-OriginalArrivalTime: 03 Oct 2003 10:28:15.0983 (UTC) FILETIME=[0E5307F0:01C38999] X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Gateway to the comp.lang.ada Usenet newsgroup List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:144 Date: 2003-10-03T06:28:15-04:00 You don't even need the Unchecked_Conversion. The following should work: function "xor"(Left,Right : in Integer) return Integer is pragma inline("xor"); type Int_As_Mod is mod 2 ** Integer'size; begin return Integer( Int_As_Mod(Left) XOR Int_As_Mod(Right) ); end "xor"; Theoretically, Unchecked_Conversion should be faster I guess. Is that why you chose it, or did you do some timing tests that showed a noticeable difference? Frank -----Original Message----- From: Steve 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)