comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Does Ada support endiannes?
Date: Thu, 15 Dec 2011 13:12:34 -0700
Date: 2011-12-15T13:12:34-07:00	[thread overview]
Message-ID: <jcdkbj$boh$1@adenine.netfront.net> (raw)
In-Reply-To: <71bc4e7f-7c23-4180-9a8d-5c880a16d0c2@p16g2000yqd.googlegroups.com>

On 12/15/2011 04:27 AM, Gerd wrote:
>
> The problem space requires integers (signed), so using unsigned is not
> the right option.

What you're talking about is not values, but bit patterns. Until you get the bit 
pattern correct, you can't think about the value. In Ada, bit patterns are 
represented by modular integers, packed arrays of Boolean, or records with 
representation clauses. Once you have the bit pattern correct, you use 
Unchecked_Conversion to interpret the bit pattern as a value of the desired type 
(signed integer in this case).

It depends on how you're getting the bytes that hold the bit pattern in question.

If you're getting individual bytes, from the network for example, then you can 
stick those bytes in the appropriate parts of a structure of the right size 
(array of 4 bytes or record containing 4 1-byte components) and 
unchecked-convert that into your target type.

If for some reason you're starting with signed integer values with the bytes 
scrambled, then you need to uncheck-convert that to get at the bit pattern, do 
the byte swapping, and uncheck-convert the result back to the target type. In 
this case, the automatic conversion between derived types with different 
representations I outlined earlier does the byte swapping for you. Of course, 
you can always unchecked-convert to a bit pattern representation and do the byte 
swapping yourself.

-- 
Jeff Carter
"I would never want to belong to any club that
would have someone like me for a member."
Annie Hall
41

--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---



  parent reply	other threads:[~2011-12-15 20:12 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-12  8:57 Does Ada support endiannes? Gerd
2011-12-12  9:23 ` Niklas Holsti
2011-12-12 11:27 ` Dmitry A. Kazakov
2011-12-12 12:44   ` Gerd
2011-12-12 19:23     ` Jeffrey Carter
2011-12-13 14:25       ` Gerd
2011-12-13 14:19     ` Gautier write-only
2011-12-14 16:16       ` Gerd
2011-12-14 18:16         ` Dmitry A. Kazakov
2011-12-14 20:16         ` Gautier write-only
2011-12-15 11:27           ` Gerd
2011-12-15 13:01             ` Simon Wright
2011-12-15 13:37             ` Dmitry A. Kazakov
2011-12-15 20:12             ` Jeffrey Carter [this message]
2011-12-12 12:46   ` Gerd
2011-12-12 13:22     ` Dmitry A. Kazakov
2011-12-12 17:07       ` Charles H. Sampson
2011-12-12 18:33         ` Dmitry A. Kazakov
2011-12-14  5:19           ` Charles H. Sampson
2011-12-14  8:56             ` Dmitry A. Kazakov
2011-12-14  9:46               ` Simon Wright
2011-12-15  9:14               ` Charles H. Sampson
2011-12-15  9:46                 ` Dmitry A. Kazakov
2011-12-25 21:42                   ` Charles H. Sampson
2011-12-26 10:47                     ` Dmitry A. Kazakov
2011-12-27 10:38                       ` Georg Bauhaus
2011-12-27 12:35                         ` Dmitry A. Kazakov
2012-01-04  4:33                       ` Charles H. Sampson
2012-01-04 11:56                         ` Dmitry A. Kazakov
2011-12-12 13:33     ` Robert A Duff
replies disabled

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