From: "Beard, Frank Randolph CIV" <frank.beard@navy.mil>
To: "Steve" <nospam_steved94@comcast.net>, <comp.lang.ada@ada-france.org>
Subject: RE: Bitwise XOR?
Date: Fri, 3 Oct 2003 06:28:15 -0400
Date: 2003-10-03T06:28:15-04:00 [thread overview]
Message-ID: <mailman.28.1065177023.25614.comp.lang.ada@ada-france.org> (raw)
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)
next reply other threads:[~2003-10-03 10:28 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-03 10:28 Beard, Frank Randolph CIV [this message]
2003-10-04 2:57 ` Bitwise XOR? Steve
2003-10-04 3:07 ` Robert I. Eachus
-- strict thread matches above, loose matches on Subject: below --
2003-10-02 1:35 David N. Maez
2003-10-02 2:03 ` sk
2003-10-02 9:01 ` John McCabe
2003-10-02 8:30 ` Adrian Knoth
2003-10-02 12:46 ` Marin David Condic
2003-10-02 12:53 ` Adrian Knoth
2003-10-02 18:15 ` Jeffrey Carter
2003-10-03 12:26 ` Marin David Condic
2003-10-03 20:32 ` Jeffrey Carter
2003-10-03 22:41 ` Marin David Condic
2003-10-03 3:14 ` Steve
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox