From: "Steve" <nospam_steved94@comcast.net>
Subject: Re: Bitwise XOR?
Date: Fri, 03 Oct 2003 03:14:31 GMT
Date: 2003-10-03T03:14:31+00:00 [thread overview]
Message-ID: <rQ5fb.663785$YN5.511353@sccrnsc01> (raw)
In-Reply-To: slrnbnnohq.26h.adi@ppc201.mipool.uni-jena.de
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1125 bytes --]
"Adrian Knoth" <adi@thur.de> wrote in message
news:slrnbnnohq.26h.adi@ppc201.mipool.uni-jena.de...
> David N. Maez <sellout@dharmadevil.com> 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...
next prev parent reply other threads:[~2003-10-03 3:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-02 1:35 Bitwise XOR? 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 [this message]
-- strict thread matches above, loose matches on Subject: below --
2003-10-03 10:28 Beard, Frank Randolph CIV
2003-10-04 2:57 ` Steve
2003-10-04 3:07 ` Robert I. Eachus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox