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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,91e38895ea853f4b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-10-26 21:26:54 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!fr.usenet-edu.net!usenet-edu.net!enst!enst.fr!not-for-mail From: "Steven Deller" Newsgroups: comp.lang.ada Subject: RE: Query on portable bit extraction Date: Sat, 27 Oct 2001 00:23:48 -0400 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: avanie.enst.fr 1004156812 48072 137.194.161.2 (27 Oct 2001 04:26:52 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Sat, 27 Oct 2001 04:26:52 +0000 (UTC) To: Return-Path: X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 Importance: Normal In-Reply-To: <3BD9FA80.C4B08A5E@acm.org> X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.6 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , List-Archive: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:15296 Date: 2001-10-27T00:23:48-04:00 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