From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: bit manipulation
Date: 1999/04/04
Date: 1999-04-04T00:00:00+00:00 [thread overview]
Message-ID: <m3emm090o7.fsf@mheaney.ni.net> (raw)
In-Reply-To: 37072A45.2B3BCE90@home.com
Jack Chow <jackchow@home.com> writes:
> Can anyone tell me how to do bit manipulation such as bitwise-and and
> bitwise or?
For modular types, of the form
type T is mod 256; -- or whatever modulus is req'd
then bitwise "and" and "or" are provided as primitive operations:
O1, O2 : T;
begin
O3 := O1 and O2;
O4 := O2 or O3;
You can also do and'ing and or'ing of boolean arrays:
type Bit_Array is array (Positive range 0 .. 7) of Boolean;
for Bit_Array'Size use 8;
pragma Pack (Bit_Array);
O1, O2 : Bit_Array;
begin
O3 := O1 and O2;
O4 := O2 or O3;
Realize that there's often a higher-level way to accomplish a goal in
Ada than in C. For example, you can declare a record and specify the
location of the components:
type RT is
record
A : Integer range 0 .. 3;
B : Integer range 0 .. 15;
C : Integer range 0 .. 3;
end record;
for RT use
record
A at 0 range 0 .. 1;
B at 0 range 2 .. 5;
C at 0 range 6 .. 7;
end record;
for RT'Size use 8;
O : RT;
begin
O.A := 1;
O.B := 2;
O.C := 0;
No bit-level manipulation of the fields is required.
You can also use the bit-manipulation facilities in the package
Interfaces, described in Annex B of your RM.
There's an online RM at the Ada home.
<http://www.adahome.com/>
next prev parent reply other threads:[~1999-04-04 0:00 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-04-04 0:00 bit manipulation Jack Chow
1999-04-04 0:00 ` Matthew Heaney [this message]
1999-04-05 0:00 ` dennison
-- strict thread matches above, loose matches on Subject: below --
2000-11-07 0:00 Bit manipulation Sandro Binetti
2000-11-07 0:00 ` Larry Kilgallen
2000-11-07 0:00 ` John English
2000-11-08 0:00 ` gdemont
2000-11-08 0:00 ` Robert Dewar
2000-11-08 0:00 ` gdemont
2000-11-08 0:00 ` Larry Kilgallen
2000-11-09 4:50 ` Robert Dewar
2000-11-10 0:00 ` Lao Xiao Hai
2000-11-09 4:47 ` Robert Dewar
2000-11-09 0:00 ` gdemont
2000-11-08 0:00 ` Sandro Binetti
2000-11-08 0:00 ` Nicolas Brunot
2000-11-08 0:00 ` gdemont
2000-11-09 4:00 ` Ken Garlington
2000-11-09 0:00 ` Larry Kilgallen
2000-11-09 0:00 ` Ken Garlington
2000-11-08 0:00 ` Dale Stanbrough
2000-11-09 0:00 ` Sandro Binetti
2000-11-09 0:00 ` gdemont
2000-11-09 0:00 ` Ken Garlington
2000-11-10 0:00 ` Scott Ingram
2000-11-09 3:59 ` Ken Garlington
2000-11-09 4:52 ` Robert Dewar
2000-11-11 0:00 ` Redryder
2000-11-11 0:00 ` Jeff Carter
2000-11-11 0:00 ` Redryder
2000-11-12 2:07 ` Ken Garlington
2000-11-12 5:56 ` Jeff Carter
2000-11-12 0:00 ` Robert Dewar
2000-11-12 0:00 ` tmoran
2000-11-13 0:00 ` Robert Dewar
2000-11-14 0:00 ` Marc A. Criley
2000-11-13 0:54 ` Ken Garlington
2000-11-12 6:40 ` tmoran
2000-11-13 0:00 ` Lutz Donnerhacke
2000-11-13 0:00 ` Robert Dewar
2000-11-13 0:00 ` Lutz Donnerhacke
2000-11-13 0:00 ` Robert Dewar
2000-11-13 0:00 ` Lutz Donnerhacke
2000-11-13 0:00 ` Pat Rogers
2000-11-13 0:00 ` Brian Rogoff
2000-11-13 0:00 ` F. Britt Snodgrass
2000-11-15 0:00 ` Lutz Donnerhacke
2000-11-13 0:00 ` Pat Rogers
2000-11-14 0:00 ` Georg Bauhaus
2000-11-15 0:00 ` Lutz Donnerhacke
2000-11-14 0:00 ` Martin Dowie
2000-11-15 0:00 ` Lutz Donnerhacke
2000-11-20 0:00 ` Randy Brukardt
2000-11-21 0:00 ` Lutz Donnerhacke
2000-11-21 0:00 ` Stephen Leake
2000-11-22 0:00 ` Lutz Donnerhacke
2000-11-13 0:00 ` Robert Dewar
2000-11-13 0:00 ` Lutz Donnerhacke
2000-11-13 0:00 ` Robert Dewar
2000-11-13 0:00 ` Lutz Donnerhacke
2000-11-08 7:18 ` Sandro Binetti
2000-11-07 0:00 ` gdemont
2000-11-08 7:22 ` Sandro Binetti
2005-02-07 12:37 Maurizio
2005-02-07 13:20 ` Martin Krischik
2005-02-07 15:32 ` Martin Dowie
2005-02-07 18:04 ` Martin Krischik
2005-02-08 0:32 ` Randy Brukardt
2005-02-08 3:11 ` Steve
2005-02-08 18:51 ` tmoran
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox