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,70ff6d6e203062f6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-28 05:21:24 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!logbridge.uoregon.edu!newsread.com!newsstand.newsread.com!POSTED.newshog.newsread.com!not-for-mail From: Peter C. Chapin Newsgroups: comp.lang.ada Subject: Re: Newbie question: How does one do bit manipulation in Ada? Message-ID: References: Organization: Kelsey Mountain Software X-Newsreader: MicroPlanet Gravity v2.50 Date: Sun, 28 Dec 2003 13:20:10 GMT NNTP-Posting-Host: 216.114.161.38 X-Complaints-To: Abuse Role , We Care X-Trace: newshog.newsread.com 1072617610 216.114.161.38 (Sun, 28 Dec 2003 08:20:10 EST) NNTP-Posting-Date: Sun, 28 Dec 2003 08:20:10 EST Xref: archiver1.google.com comp.lang.ada:3883 Date: 2003-12-28T13:20:10+00:00 List-Id: In article , stephen_leake@acm.org says... > Others have told you how to do this using XOR. > > I'd like to point out that Ada often has better ways to accomplish > things that are done with bit-fiddling in other languages. So if you > can explain why you need to invert those bits, we might be able to > give you a better way to accomplish the same thing. Sorry about the long delay for this follow-up; I've been away for the Christmas holiday. Anyway, I can appreciate that there might be a better way to accomplish what I'm trying to do. My little program is trying to experiment with the effectiveness of different checksumming techniques. I made a package that simulates a noisy channel (random noise). The package has a procedure to set the bit error rate and another procedure, Transceive, that is intended to accept an 8 bit octet and then randomly change some bits in that octet according to the selected bit error rate. It then hands back the result. The main program generates random data, computes checksums on this data in various ways, and then passes the data, together with the checksums, through the simulated noisy channel. By comparing the result with the original data it can count the number of erronous bits. It can also verify the checksum and thus find out if the checksum used was able to detect the error. After using a large number of data blocks one can accumulate statistically significant results. The program shows, for example, that your typical CRC checksum does a much better job at detecting errors than, for example, a simple checksum using the same space overhead. There is nothing revolutionary in this, of course. As I said, this is just a toy program that I'm using right now to help me learn Ada. Anyway, I have yet to deal with writing CRC checksumming code in Ada (that's for later). At the moment I'm getting my noisy channel simulation to work. My Transceive procedure works by looping over the eight bits in an octet and, if a particular bit is to be corrupted, XORing a suitable mask into the number to invert the bit. The C program that I wrote originally uses the type int for the simulated octets. My first pass at an Ada translation thus used Integer. However, I can see that Integer is not entirely the most appropriate type here so I have no problem using one of the modular types (or a subtype thereof). In fact, I could even use a record type of some kind if there was some advantage to doing so. I don't actually use the data for anything aside from this simulation; an array of 8 boolean values would work for me. Hmmmm. Peter