comp.lang.ada
 help / color / mirror / Atom feed
From: "Steven Deller" <deller@smsail.com>
To: <comp.lang.ada@ada.eu.org>
Subject: RE: Query on portable bit extraction
Date: Sat, 27 Oct 2001 00:23:48 -0400
Date: 2001-10-27T00:23:48-04:00	[thread overview]
Message-ID: <mailman.1004156810.28692.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: <3BD9FA80.C4B08A5E@acm.org>

The issue with byte ordering actually has more to do with how you got
the data.  If you get the data as a byte stream and define an array of
bytes, then the only issue is bit order within each byte.  On the other
hand, if you get the data 4-bytes at a time "in parallel", you will need
to do byte swapping to get the fields to be adjacent.  If you get the
data one-bit at a time, then no byte swapping is needed and fields will
always be adjacent bits, regardless of the architecture.

I'm *guessing* that for the problem at hand, you received the data byte
by byte on a little-endian machine where you *defined* adjacent bits
(across bytes) using little-endian definitions of what it means to cross
a byte boundary.  If you now take that data 4-bytes at a time and send
that to big-endian machine, you will have to do byte swapping (end for
end) across the word to get fields that are adjacent (and if fields
cross 4-byte boundaries, you will have to do word swapping).  Once you
have done that, you need only count in the correct direction to see the
fields.

Its hard to describe in email, but you can probably figure it out if you
realize that size of units when exchanging data determines what type of
byte swapping is necessary (none, 2-byte pairs, 4-byte quads, 8-byte
octets, etc).

That is why this is a hard problem.  There is no *general* solution
until you know your channel width.

Regards,
Steve

> -----Original Message-----
> From: comp.lang.ada-admin@ada.eu.org 
> [mailto:comp.lang.ada-admin@ada.eu.org] On Behalf Of Jeffrey Carter
> Sent: Friday, October 26, 2001 8:07 PM
> To: comp.lang.ada@ada.eu.org
> Subject: Re: Query on portable bit extraction
> 
> 
> I would recommend using a collection of bytes and ensuring 
> that the same bytes contain the same values on all platforms. 
> Then extract the desired parts of the desired bytes, 
> combining them as required.
> 
> You can also, if you're sure the same bytes have the same 
> values, combine bytes into larger values using type 
> conversions and shifts or
> multiplications:
> 
> T1 := Shift_Left (Unsigned_16 (Byte_21), 8) or Unsigned_16 
> (Byte_22); T2 := Shift_Right (T1, 6) and 2#0111_1111#; -- YYY_YYYY
> 
> Both work correctly regardless of endianness;
> 
> -- 
> Jeff Carter
> "I wave my private parts at your aunties."
> Monty Python & the Holy Grail 
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org 
> http://ada.eu.org/mailman/listinfo/comp.lang.ad> a




  reply	other threads:[~2001-10-27  4:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-26 16:49 Query on portable bit extraction Mark Johnson
2001-10-26 17:08 ` Lutz Donnerhacke
2001-10-27  0:06 ` Jeffrey Carter
2001-10-27  4:23   ` Steven Deller [this message]
2001-10-27 16:31     ` Nick Roberts
2001-10-28  1:30       ` Jeffrey Carter
2001-10-28 19:07         ` Bit_Order useful [was Query on portable bit extraction] Nick Roberts
2001-10-29  1:23           ` Robert Dewar
2001-10-29  1:25       ` Query on portable bit extraction Robert Dewar
replies disabled

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