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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,255a2533fba89f5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-09-16 11:58:43 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3D8629D3.2040603@acm.org> From: Jeffrey Carter User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Calculate and set Parity References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 16 Sep 2002 18:58:44 GMT NNTP-Posting-Host: 63.184.9.154 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 1032202724 63.184.9.154 (Mon, 16 Sep 2002 11:58:44 PDT) NNTP-Posting-Date: Mon, 16 Sep 2002 11:58:44 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:29042 Date: 2002-09-16T18:58:44+00:00 List-Id: Sebastian wrote: > I need a subroutine that calculates the parity of a record type with the > size of 16 bits. Is there some nice way > to do this? I currently have a solution were I use Unchecked_Conversion to > convert my variable to an > array booleans, then I calculate every true etc. Is there some way to do > this without using Unchecked_Conversion. Well, you could always try * using a machine code insertion * using an imported C subprogram * passing an address and size but it you want it to be safe and readable, unchecked conversion to an array of Boolean seems like a good way to go. You then simply add up the Boolean'Pos of each element and determine if the result is even or odd ("rem 2"). You could do an unchecked conversion to a 16-bit modular type and use shifts and masks to isolate the individual bits, but using Booleans seems simpler. -- Jeff Carter "Oh Lord, bless this thy hand grenade, that with it thou mayst blow thine enemies to tiny bits, in thy mercy." Monty Python and the Holy Grail