comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org>
Subject: Re: Bit operations in Ada
Date: Fri, 23 May 2008 23:25:49 GMT
Date: 2008-05-23T23:25:49+00:00	[thread overview]
Message-ID: <1oIZj.177005$yE1.5567@attbi_s21> (raw)
In-Reply-To: <g17cct$cup$1@aioe.org>

Dennis Hoppe wrote:
> 
> 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 started with an array of booleans of size 2**n, that provides neat 
> access to individual bits by means of an index. Unfortunately, 
> addition/subtraction mod 2**n is not supported, but essential for me.

Arrays of Boolean certainly seem nice for direct bit access, until you realize 
that the language does not define what bit corresponds to which index value, and 
any such code is completely compiler-dependent and non-portable, and you have to 
experiment with each compiler/platform combination to figure out how it works there.

Modular types require creating a mask and applying it to the value correctly to 
access or change individual bits, but once this is done correctly, the 
operations are reusable and compiler- and platform independent, so I generally 
prefer this approach.

Shift and rotation operations are restricted to the modular types in Interfaces, 
for some reason; I think this decision was probably a mistake. But it's not a 
major impediment to getting things done.

-- 
Jeff Carter
"Beyond 100,000 lines of code you
should probably be coding in Ada."
P. J. Plauger
26



      parent reply	other threads:[~2008-05-23 23:25 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 ` Bit operations in Ada Robert A Duff
2008-05-24  0:27   ` Randy Brukardt
2008-05-24  9:40   ` Bit operations in Ada (Thank you) Dennis Hoppe
2008-05-23 23:25 ` Jeffrey R. Carter [this message]
replies disabled

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