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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham 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 19:57:39 PST Path: archiver1.google.com!news2.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!ucberkeley!newsfeed.mathworks.com!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc52.ops.asp.att.net.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: rwcrnsc52.ops.asp.att.net 1065236258 12.211.13.75 (Sat, 04 Oct 2003 02:57:38 GMT) NNTP-Posting-Date: Sat, 04 Oct 2003 02:57:38 GMT Organization: Comcast Online Date: Sat, 04 Oct 2003 02:57:38 GMT Xref: archiver1.google.com comp.lang.ada:192 Date: 2003-10-04T02:57:38+00:00 List-Id: The unchecked conversion must be used is to avoid the range check. For example, the following code causes a a range check exception: declare a : Integer; b : Integer; begin a := -1; b := 1; result := a xor b; end; Steve (The Duck) "Beard, Frank Randolph CIV" wrote in message news:mailman.28.1065177023.25614.comp.lang.ada@ada-france.org... 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)