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=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,43ad9ab56ebde91c X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.189.233 with SMTP id gl9mr5936926pbc.8.1323979957095; Thu, 15 Dec 2011 12:12:37 -0800 (PST) Path: lh20ni26445pbb.0!nntp.google.com!news2.google.com!news.glorb.com!news.netfront.net!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: Does Ada support endiannes? Date: Thu, 15 Dec 2011 13:12:34 -0700 Organization: Also freenews.netfront.net; news.tornevall.net Message-ID: References: <23835087-313f-427c-b37e-4ff1bdef9d57@r6g2000yqr.googlegroups.com> <108d5437-ae36-4e79-ad4e-aab3b903d0f4@gl2g2000vbb.googlegroups.com> <2f9744b6-4a45-4dd1-9621-c6f5d10166cb@r6g2000yqr.googlegroups.com> <0a7b55fd-1ecf-4a40-979c-12ce44071be9@p9g2000vbb.googlegroups.com> <6779f55b-e110-4673-b70b-cbd7c58f5d78@j10g2000vbe.googlegroups.com> <71bc4e7f-7c23-4180-9a8d-5c880a16d0c2@p16g2000yqd.googlegroups.com> NNTP-Posting-Host: 97.215.82.138 Mime-Version: 1.0 X-Trace: adenine.netfront.net 1323979956 12049 97.215.82.138 (15 Dec 2011 20:12:36 GMT) X-Complaints-To: news@netfront.net NNTP-Posting-Date: Thu, 15 Dec 2011 20:12:36 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15 In-Reply-To: <71bc4e7f-7c23-4180-9a8d-5c880a16d0c2@p16g2000yqd.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2011-12-15T13:12:34-07:00 List-Id: 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 ---