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,705f377a5e04a446 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!198.186.194.249.MISMATCH!transit3.readnews.com!news-out.readnews.com!news-xxxfer.readnews.com!panix!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Bit operations in Ada Date: Fri, 23 May 2008 18:38:50 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1211582331 29953 192.74.137.71 (23 May 2008 22:38:51 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 23 May 2008 22:38:51 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:ntFiQpb5LRk9Fl+4vGJ8WGeqhro= Xref: g2news1.google.com comp.lang.ada:305 Date: 2008-05-23T18:38:50-04:00 List-Id: Dennis Hoppe writes: > Hello, > > 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'm curious why you want to do all these things on the same type. You say, "My objective is...", but what's the higher-level objective? Anyway, I would use Unchecked_Conversion between a modular type and a packed array of Boolean, as suggested by Ludovic Brenta. Possibly wrapped in useful functions. Instead of pragma Pack, I would use "for Bit_Field'Component_Size use 1;". They both do the same thing, but conceptually, "pack" means "I want small things, so whole-object operations are faster, at the expense of per-component operations", whereas the Component_Size clause means "I depend on the exact bit size for correctness". - Bob