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,FREEMAIL_FROM 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 10:40:15 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!easynews.com!easynews!bigfeed2.bellsouth.net!news.bellsouth.net!elnk-atl-nf1!newsfeed.earthlink.net!border2.nntp.ash.giganews.com!border1.nntp.ash.giganews.com!firehose2!nntp4!intern1.nntp.aus1.giganews.com!nntp.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 28 Dec 2003 12:40:13 -0600 Date: Sun, 28 Dec 2003 13:40:12 -0500 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Newbie question: How does one do bit manipulation in Ada? References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 24.34.214.193 X-Trace: sv3-6e7RFO1HEMlZ7/Iy+bVKgIvxkDOvoV52kWcVuqqWyik968eEhmVNLsxJnz5D56W2YKLOmyZs+avNY4+!vxgiVMSLPJQ14dI8wDEnquZbwz/yP6Bql1+Ttbd1GQSoOz0rD16me/r+AvGeSA== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: archiver1.google.com comp.lang.ada:3894 Date: 2003-12-28T13:40:12-05:00 List-Id: Peter C. Chapin wrote: > 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. You could certainly do this in Ada with say: type Octet is mod 256; for Octet'Size use 8; -- optional, doesn't affect semantics. But first you should think about where you want to go with this. Right now you are doing unbiased errors. You could also OR 1 and AND 0 error bits in to create a bias toward one or zero. You might also want to implement the error generator as a finite state machine to create burst errors: type State is (Clear, Burst); Current: State := Clear; function Error return Boolean is begin case Current is when Clear => if Random < 0.01 then Current := Burst; return True; else Return False; end if; when Burst => if Random < 0.5 then Current := Clear; return False; else return True; end if; end case; end Error; (You really should start the error generator in a state chosen based on the calculated probability from the generator. I'd just throw the first few dozen bytes away...) As for the choice between a boolean array and a modular type for Octet, it is a close call. Or you could even convert back and forth. Personally, I would use the modular type, and generate error bytes by: function Error_Octet is Result: Octet := 0; begin for I in 1..8 loop Result := Result + Result; -- or 2 * Result; if Error then Result := Result + 1; end loop; return Result; end Error_Octet; Seems simple enough, and allows Error to be as complex a function as you want. In any case, I think you probably want to count an octet as an error if any bits were flipped, and are not really planning on counting the number of errors in a > > 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 -- Robert I. Eachus "The war on terror is a different kind of war, waged capture by capture, cell by cell, and victory by victory. Our security is assured by our perseverance and by our sure belief in the success of liberty." -- George W. Bush