comp.lang.ada
 help / color / mirror / Atom feed
From: Peter C. Chapin <pchapin@sover.net>
Subject: Re: Newbie question: How does one do bit manipulation in Ada?
Date: Sun, 28 Dec 2003 13:20:10 GMT
Date: 2003-12-28T13:20:10+00:00	[thread overview]
Message-ID: <MPG.1a58a29890dcd92f989686@news.sover.net> (raw)
In-Reply-To: mailman.170.1072170574.31149.comp.lang.ada@ada-france.org

In article <mailman.170.1072170574.31149.comp.lang.ada@ada-france.org>, 
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



  reply	other threads:[~2003-12-28 13:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-23  1:58 Newbie question: How does one do bit manipulation in Ada? Peter C. Chapin
2003-12-23  3:01 ` Georg Bauhaus
2003-12-23  3:23   ` Peter C. Chapin
2003-12-23  3:36     ` tmoran
2003-12-23  3:33 ` Steve
2003-12-23  9:09 ` Stephen Leake
2003-12-28 13:20   ` Peter C. Chapin [this message]
2003-12-28 18:40     ` Robert I. Eachus
2003-12-29  2:57       ` Peter C. Chapin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox