From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,553a6b79b2471571 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!p79g2000cwp.googlegroups.com!not-for-mail From: "jimmaureenrogers@worldnet.att.net" Newsgroups: comp.lang.ada Subject: Re: How do you bitwise operations in Ada '83 and '95 Date: 18 Jul 2006 11:53:20 -0700 Organization: http://groups.google.com Message-ID: <1153248800.834457.183940@p79g2000cwp.googlegroups.com> References: <1153244316.853254.291560@m79g2000cwm.googlegroups.com> NNTP-Posting-Host: 69.170.65.169 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1153248804 7768 127.0.0.1 (18 Jul 2006 18:53:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 18 Jul 2006 18:53:24 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: p79g2000cwp.googlegroups.com; posting-host=69.170.65.169; posting-account=SqOfxAwAAAAkL81YAPGH1JdBwpUXw9ZG Xref: g2news2.google.com comp.lang.ada:5777 Date: 2006-07-18T11:53:20-07:00 List-Id: 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