comp.lang.ada
 help / color / mirror / Atom feed
From: Tucker Taft <stt@averstar.com>
Subject: Re: First time Ada has let me down
Date: Thu, 26 Oct 2000 17:46:58 -0400
Date: 2000-10-26T21:46:58+00:00	[thread overview]
Message-ID: <39F8A652.96835CB7@averstar.com> (raw)
In-Reply-To: 8FD7DEBEEsynoptikdamudderfuck@news

You have received a bunch of answers, not all relevant
to Ada 83.  It is true that Ada 83 doesn't have support
for bit-wise "and"/"or" on integers.  However, it has
several other features that make that unnecessary.

Defining a record type with fields of a 4-bit
type (such as "type Bit4 is range 0..15;")
and then putting a record representation clause
on it would seem to be a good starting point.

If you really want to manipulate bits, a packed
array of boolean does have "and" and "or", and
gives you complete access to individual bits.

Finally, you could define a packed array of the 4-bit type
(such as the one defined above), and use that to get
at individual "nibbles".

Unchecked conversion may be necessary somewhere along the
way, unless you can use an appropriate rep-spec'ed record or a
packed array to represent the entire packet.

Although a packed boolean array most directly matches
the (limited ;-) capabilities of C, the other mechanisms (such 
as rep-speced records, or packed array of 4-bit elements)
are probably a better fit for the problem.

Shifty wrote:
> 
> OK, here's the story:
> 
> I had a problem at work where I needed to calculate the offset of a
> "magic number" within a buffer containing an IP datagram.
> 
> The magic number is 3 protocol headers deep within the datagram, and
> all three headers are variable length.  I needed to find the HLEN
> fields of the IP and TCP headers in memory.  Turns out both of these
> are stored in 4 bits.  The data in the other 4 bits of the octet
> belong to another field in the header.

> ... I can't believe Ada (83) doesn't have native
> language support for these!!!  Please tell me that I am hopelessly
> confused and dead wrong!
> 
> Cheers,
> Andrew.

-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Commercial Division, AverStar (formerly Intermetrics)
(http://www.averstar.com/services/IT_consulting.html)  Burlington, MA  USA



      parent reply	other threads:[~2000-10-26 21:46 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-25  3:50 First time Ada has let me down Shifty
2000-10-25  0:00 ` First time Ada has let me down (recipe) Guillaume
2000-10-26  2:45   ` Mats Weber
2000-10-25  0:00 ` First time Ada has let me down wv12
2000-10-25  0:00   ` Gisle Sælensminde
2000-10-25  0:00   ` Joel Seidman
2000-10-25  0:00   ` Gautier
2000-10-26  6:42   ` tmoran
2000-10-25  0:00 ` Larry Kilgallen
2000-10-25  0:00   ` Ted Dennison
2000-10-25  0:00     ` Larry Kilgallen
2000-10-25  0:00       ` Ted Dennison
2000-10-25  0:00 ` Ken Garlington
2000-10-25  0:00   ` Shifty
2000-10-26  4:00     ` Jeff Carter
2000-10-26 14:43       ` Ted Dennison
2000-10-26 17:55         ` tmoran
2000-10-26 17:12       ` Shifty
2000-10-27  1:00         ` Jeff Carter
2000-10-26 22:27       ` Guillaume
2000-10-26 21:49         ` Keith Thompson
2000-10-26 14:36     ` Ted Dennison
2000-10-26 17:55       ` tmoran
2000-10-26 23:08         ` Ted Dennison
2000-10-25  4:44 ` Julian Morrison
2000-10-25  4:50 ` Ted Dennison
2000-10-24  0:00   ` Keith Thompson
2000-10-26  0:00   ` Andreas Schulz
2000-10-26 18:05     ` Alejandro Villanueva
2000-10-26 21:46 ` Tucker Taft [this message]
replies disabled

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