comp.lang.ada
 help / color / mirror / Atom feed
From: Adrian Knoth <adi@thur.de>
Subject: Re: Bitwise XOR?
Date: 2 Oct 2003 08:30:50 GMT
Date: 2003-10-02T08:30:50+00:00	[thread overview]
Message-ID: <slrnbnnohq.26h.adi@ppc201.mipool.uni-jena.de> (raw)
In-Reply-To: nhLeb.476768$Oz4.309292@rwcrnsc54

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.

I did it some time ago, I'm not sure whether it is right, perhaps
it should be done on mod-datatypes.

   function "xor" (Left, Right : in Integer) return Integer is
      result : Integer := 0;
      leftrest : Integer := Left;
      rightrest : Integer := Right;
      boolleft, boolright : Boolean;

   begin
      for I in 0 .. Integer'Size - 1 loop
         if (leftrest mod 2 = 1) then
            boolleft := True;
         else
            boolleft := False;
         end if;

         leftrest := leftrest / 2;
         if (rightrest mod 2 = 1) then
            boolright := True;
         else
            boolright := False;
         end if;
         rightrest := rightrest / 2;

         if (boolleft xor boolright) then
            result := result + 2**(I);
         end if;
      end loop;

      return result;
   end "xor";


-- 
mail: adi@thur.de  	http://adi.thur.de	PGP: v2-key via keyserver

M�nner sind wie Jeans: blau und steif...



  parent reply	other threads:[~2003-10-02  8:30 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 [this message]
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
  -- 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