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!wns13feed!worldnet.att.net!attbi_s21.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Bit operations in Ada References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <1oIZj.177005$yE1.5567@attbi_s21> NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s21 1211585149 12.201.97.213 (Fri, 23 May 2008 23:25:49 GMT) NNTP-Posting-Date: Fri, 23 May 2008 23:25:49 GMT Organization: AT&T ASP.att.net Date: Fri, 23 May 2008 23:25:49 GMT Xref: g2news1.google.com comp.lang.ada:309 Date: 2008-05-23T23:25:49+00:00 List-Id: Dennis Hoppe wrote: > > 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 started with an array of booleans of size 2**n, that provides neat > access to individual bits by means of an index. Unfortunately, > addition/subtraction mod 2**n is not supported, but essential for me. Arrays of Boolean certainly seem nice for direct bit access, until you realize that the language does not define what bit corresponds to which index value, and any such code is completely compiler-dependent and non-portable, and you have to experiment with each compiler/platform combination to figure out how it works there. Modular types require creating a mask and applying it to the value correctly to access or change individual bits, but once this is done correctly, the operations are reusable and compiler- and platform independent, so I generally prefer this approach. Shift and rotation operations are restricted to the modular types in Interfaces, for some reason; I think this decision was probably a mistake. But it's not a major impediment to getting things done. -- Jeff Carter "Beyond 100,000 lines of code you should probably be coding in Ada." P. J. Plauger 26