comp.lang.ada
 help / color / mirror / Atom feed
From: Dale Stanbrough <dale@cs.rmit.edu.au>
Subject: Re: logical operations in Ada
Date: Tue, 13 Feb 2001 06:43:00 GMT
Date: 2001-02-13T06:43:00+00:00	[thread overview]
Message-ID: <dale-043811.17351013022001@news-server> (raw)
In-Reply-To: 512i6.239390$JT5.8526649@news20.bellglobal.com

Freelancer wrote:

> I am well aware of ada.characters.handling. That isn't my objective.
> As you said, I am trying to fiddle with bits. How to do this in Ada?
> 
> A small example would be greatly appreciated. :)
> Thank you for your references though.

You can use the appropriate routines, either by converting to 
an unsigned type, or to a packed boolean type.


e.g.

   type Bit_Array is array (natural range <>) of Boolean;

   subtype Bit_Array_32 is Bit_Array (0..31);
   pragma Pack (Bit_Array_32);


   X : Bit_Array_32;
   X (1) := True;
   X := not X;
   X := X xor X;

or...

   Item : Interfaces.Unsigned_16;

   Item := Item xor 2#0000_0000_1111_1010#;


You can use Unchecked_Conversion to convert back and forth
b/w your favourite type to do an even wider range of bit 
fiddling.


Dale



  reply	other threads:[~2001-02-13  6:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-11  9:52 logical operations in Ada Freelancer
2001-02-11 12:24 ` David C. Hoos, Sr.
2001-02-11 12:59 ` Florian Weimer
2001-02-13  3:40   ` Freelancer
2001-02-13  6:43     ` Dale Stanbrough [this message]
2001-02-13 11:54     ` Jeff Creem
2001-02-13 17:44     ` David C. Hoos, Sr.
2001-02-13 22:11       ` Florian Weimer
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox