From: "jimmaureenrogers@worldnet.att.net" <jimmaureenrogers@worldnet.att.net>
Subject: Re: How do you bitwise operations in Ada '83 and '95
Date: 18 Jul 2006 11:53:20 -0700
Date: 2006-07-18T11:53:20-07:00 [thread overview]
Message-ID: <1153248800.834457.183940@p79g2000cwp.googlegroups.com> (raw)
In-Reply-To: 1153244316.853254.291560@m79g2000cwm.googlegroups.com
Chris L wrote:
> Also, do you have small coding examples that demonstrate this?
Bitwise operations in Ada 83 are accomplished through packed
arrays of boolean. In Ada 95 you can also accomplish
bit-wise operations (and, or, xor) on modular types.
The following example shows bit-wise operations using a
packed array of boolean. The small program computes prime
number using a sieve of Erastosthenese. The array flagging
found values is implemented as a packed array of boolean.
Notice that individual bits are directly addressable as array
elements in a packed array of boolean.
with Ada.Command_Line;use Ada.Command_Line;
with Ada.Text_Io;use Ada.Text_Io;
with Ada.Integer_Text_Io;use Ada.Integer_Text_Io;
procedure Nsievebits is
function Count (M : in Natural ) return Natural is
type Boolean_Array is array (2 .. M) of Boolean;
pragma Pack (Boolean_Array);
C : Natural := 0;
S : Boolean_Array := (others => True);
I : Positive;
begin
for K in S'range loop
if S(K) then
C := C + 1;
I := K;
loop
I := I + K;
exit when I > M;
S(I) := False;
end loop;
end if;
end loop;
return C;
end Count;
procedure Run (N : in Natural ) is
M : Natural;
begin
M := 2 ** N * 10_000;
Put ("Primes up to ");
Put (Item => M, Width => 8);
Put (Item => Count (M), Width => 8);
New_Line;
end Run;
N : constant Natural := Natural'Value (Argument (1));
begin
Run (N);
Run (N - 1);
Run (N - 2);
end Nsievebits;
Jim Rogers
next prev parent reply other threads:[~2006-07-18 18:53 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1153244316.853254.291560@m79g2000cwm.googlegroups.com>
2006-07-18 18:45 ` How do you bitwise operations in Ada '83 and '95 Robert A Duff
2006-07-18 18:53 ` jimmaureenrogers [this message]
2006-07-18 19:22 ` Jeffrey R. Carter
2006-07-18 21:32 ` jimmaureenrogers
2006-07-19 0:40 ` Jeffrey R. Carter
2006-07-19 3:55 ` jimmaureenrogers
2006-07-19 4:37 ` Jeffrey R. Carter
2006-07-19 13:05 ` jimmaureenrogers
2006-07-19 19:43 ` Jeffrey R. Carter
[not found] ` <1153313832.389434.144930@s13g2000cwa.googlegroups.com>
2006-07-19 13:55 ` Georg Bauhaus
2006-07-19 14:20 ` Robert A Duff
2006-07-19 19:30 ` Jeffrey R. Carter
2006-07-19 14:41 ` Robert A Duff
2006-07-18 19:21 ` Jeffrey R. Carter
2006-07-19 3:01 ` tmoran
[not found] <9315684D-C216-4EDA-8852-0A6BD4C275B0@amado-alves.info>
2006-07-19 22:30 ` Marius Amado-Alves
2006-07-20 7:40 ` Georg Bauhaus
2006-07-20 9:29 ` Colin Paul Gloster
2006-07-20 12:31 ` Georg Bauhaus
2006-07-20 13:08 ` Colin Paul Gloster
2006-07-20 13:29 ` Marius Amado-Alves
2006-07-20 13:49 ` Georg Bauhaus
2006-07-21 5:23 ` Colin Paul Gloster
2006-07-21 8:00 ` Georg Bauhaus
2006-07-20 9:03 ` Stephen Leake
2006-07-20 9:38 ` Marius Amado-Alves
2006-07-21 9:53 ` Stephen Leake
2006-07-20 11:31 ` Dmitry A. Kazakov
2006-07-20 13:18 ` Marius Amado-Alves
2006-07-21 9:58 ` Stephen Leake
2006-07-21 12:09 ` Dmitry A. Kazakov
2006-07-21 19:03 ` Simon Wright
2006-07-22 8:32 ` Dmitry A. Kazakov
2006-07-22 8:57 ` Simon Wright
2006-07-22 10:52 ` Georg Bauhaus
2006-07-22 13:31 ` Dmitry A. Kazakov
2006-07-20 9:39 Fwd: " Marius Amado-Alves
2006-07-20 17:54 ` tmoran
2006-07-20 18:30 ` Marius Amado-Alves
2006-07-20 19:36 ` tmoran
2006-07-20 22:09 ` Simon Wright
2006-07-21 10:07 ` Stephen Leake
2006-07-21 19:09 ` Simon Wright
2006-07-21 19:45 ` tmoran
2006-07-23 15:59 ` Stephen Leake
2006-07-24 6:08 ` Simon Wright
[not found] <BFF12262-F906-4F9A-B867-D0373609F038@amado-alves.info>
2006-07-20 16:40 ` Marius Amado-Alves
[not found] <CD6E3BB8-52D2-4EED-A790-0184FE56A99A@amado-alves.info>
2006-07-20 20:41 ` Marius Amado-Alves
2006-07-20 23:13 ` Randy Brukardt
2006-07-21 5:38 ` Marius Amado-Alves
2006-07-21 22:09 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox