comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Bit operations in Ada
Date: Fri, 23 May 2008 18:38:50 -0400
Date: 2008-05-23T18:38:50-04:00	[thread overview]
Message-ID: <wcc63t4ejd1.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: g17cct$cup$1@aioe.org

Dennis Hoppe <dennis.hoppe@hoppinet.de> writes:

> Hello,
>
> I'm new to Ada and bitwise operations is a new challenge in this
> realm. My objective is to manipulate some bit strings in Ada, especially:
>
> a) addition/subtraction mod 2**n,
> b) change bits directly (e.g, via array access)
> c) shift operations
> d) rotate operations
> e) and, xor, not, or

I'm curious why you want to do all these things on the same type.
You say, "My objective is...", but what's the higher-level objective?

Anyway, I would use Unchecked_Conversion between a modular type and a
packed array of Boolean, as suggested by Ludovic Brenta.
Possibly wrapped in useful functions.

Instead of pragma Pack, I would use
"for Bit_Field'Component_Size use 1;".
They both do the same thing, but conceptually, "pack" means
"I want small things, so whole-object operations are faster,
at the expense of per-component operations", whereas the
Component_Size clause means "I depend on the exact bit size
for correctness".

- Bob



  parent reply	other threads:[~2008-05-23 22:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-23 21:19 Bit operations in Ada Dennis Hoppe
2008-05-23 22:08 ` Ludovic Brenta
2008-05-24 15:36   ` Simon Wright
2008-06-02 13:27     ` Bit operations in Ada (endianness) Dennis Hoppe
2008-06-02 14:01       ` (see below)
2008-06-02 18:22         ` Jeffrey R. Carter
2008-06-02 17:38       ` Ludovic Brenta
2008-05-23 22:38 ` Robert A Duff [this message]
2008-05-24  0:27   ` Bit operations in Ada Randy Brukardt
2008-05-24  9:40   ` Bit operations in Ada (Thank you) Dennis Hoppe
2008-05-23 23:25 ` Bit operations in Ada Jeffrey R. Carter
replies disabled

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