comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: bitwise operations in Ada95
Date: Wed, 18 Jul 2001 02:43:30 GMT
Date: 2001-07-18T02:43:30+00:00	[thread overview]
Message-ID: <mJ657.222507$%i7.125600779@news1.rdc1.sfba.home.com> (raw)
In-Reply-To: 9j2p76$6is$1@fang.dsto.defence.gov.au

> Is there a way of performing bitwise operations on basic
> types, e.g, integers, floats etc as in the bitwise and '&' and
> bitwise or '|' in c.
    In Ada you can do logical operations on arrays of booleans.
If space is a consideration you can use pragma pack.  If that is
the wrong abstraction, you do bitwise "and" and "or" on modular
types, and you can convert integers to and from modular types if
they have the same size and you don't get in trouble with the
sign bit.  This won't work in general for floating point types,
clearly, so there you would have to use Unchecked_Conversion to
and from a suitable modular type.  If you are trying to mask
the exponent or mantissa of a float, conversion to a suitable
record, and then use of elements of the record, would probably
be more appropriate.
   The general answer to "is there a way ... as in c" is yes,
though perhaps not at the same abstraction level.



  reply	other threads:[~2001-07-18  2:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-18  1:28 bitwise operations in Ada95 Vladimir Bednikov
2001-07-18  2:43 ` tmoran [this message]
2001-07-18  9:50 ` Lutz Donnerhacke
2001-07-18 15:42   ` Aquaman
2001-07-18 16:09     ` Jacob Sparre Andersen
2001-07-19  9:03       ` Jacob Sparre Andersen
2001-07-18 20:17     ` Sune Falck
replies disabled

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