From: Bernd.Specht@gmx.com (Bernd Specht)
Subject: Re: Bitmanipulation in Ada
Date: 19 Aug 2004 17:46:56 GMT
Date: 2004-08-19T19:46:56+02:00 [thread overview]
Message-ID: <Xns954AC90C25B22BerndSpechgmxcom@151.189.20.10> (raw)
In-Reply-To: cg0j57$bal$1@sparta.btinternet.com
Many thanks, this will help me a lot.
"Martin Dowie" <martin.dowie@btopenworld.com> wrote in
news:cg0j57$bal$1@sparta.btinternet.com:
> Bernd Specht wrote:
>> 2. I did not found shift and rotate operations. Did I miss something
>> or are there really none?
>
> Check out package "Interfaces" they are all there - as are some common
> predefined types.
>
>> 3. When I want treat a value both as an integer and as a boolean
>> array, how can i do this? In pascal I would use a tagless record like
>
> Assuming you had a _really_ good reason to need to think of the data in
> both terms, you have a number of options:
>
> 1) Unchecked_Conversion;
>
> procedure Foo (Y : Unsigned_8) is
> procedure To_Array_8 is
> new Ada.Unchecked_Conversion (Unsigned_8, Array_8);
> X : Array_8 := To_Array_8 (Y);
> begin
> ...
>
> 2) Address clause to 'overlay' 2 variables at the same address;
>
> procedure Foo (Y : Unsigned_8) is
> X : Array_8;
> for X'Address use Y'Address;
> begin
> ...
>
> 3) Variant record with a representation clause;
>
> type Variant (Is_Array : Boolean := False) is
> record
> case Is_Array is
> when False =>
> U : Unsigned_8;
> when True =>
> A : Array_8;
> end case;
> end record;
> for Variant use
> record
> U at 0 range 0 .. 7;
> A at 0 range 0 .. 7;
> end record;
>
> This will leave it to the compiler where to put "Is_Array"
>
> There are pros and cons to each - I'd rather use
> Ada.Unchecked_Conversion to make it explicit that I'm switching
> representations.
>
> Cheers
>
> -- Martin
>
>
next prev parent reply other threads:[~2004-08-19 17:46 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-18 20:37 Bitmanipulation in Ada Bernd Specht
2004-08-18 20:51 ` Ludovic Brenta
2004-08-18 21:10 ` Bernd Specht
2004-08-18 21:16 ` Ludovic Brenta
2004-08-18 21:18 ` Ed Falis
2004-08-19 17:30 ` Bernd Specht
2004-08-19 17:44 ` Ed Falis
2004-08-19 0:53 ` Jeffrey Carter
2004-08-19 17:44 ` Bernd Specht
2004-08-19 18:09 ` Martin Dowie
2004-08-19 18:28 ` Bernd Specht
2004-08-19 19:31 ` Martin Dowie
2004-08-19 20:29 ` Martin Dowie
2004-08-20 21:31 ` Bernd Specht
2004-08-19 19:17 ` Jeffrey Carter
2004-08-19 19:57 ` Björn Persson
2004-08-20 0:52 ` Jeffrey Carter
2004-08-19 21:24 ` Francois G. Dorais
2004-08-20 8:55 ` Pascal Obry
2004-08-20 7:26 ` Jean-Pierre Rosen
2004-08-20 21:20 ` Bernd Specht
2004-08-20 21:39 ` Ed Falis
2004-08-18 21:14 ` (see below)
2004-08-18 21:56 ` Martin Dowie
2004-08-19 15:25 ` (see below)
2004-08-19 15:50 ` Martin Dowie
2004-08-18 21:53 ` Martin Dowie
2004-08-18 22:59 ` Björn Persson
2004-08-19 8:08 ` Egil H. H�vik
2004-08-19 17:46 ` Bernd Specht [this message]
2004-08-20 20:57 ` Bitordering? was " Alfred Hilscher
2004-08-21 11:34 ` Nick Roberts
2004-08-21 14:00 ` Jim Rogers
2004-08-21 16:54 ` Simon Wright
2004-08-21 16:55 ` Georg Bauhaus
2004-08-23 18:36 ` Alfred Hilscher
2004-08-23 18:47 ` Alfred Hilscher
2004-08-23 22:39 ` Nick Roberts
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox