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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8200c5d9633351c4 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news4.google.com!news.glorb.com!newsgate.cistron.nl!newsfeed.stueberl.de!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: How to byte swap an IEEE Float? Date: Tue, 28 Jun 2005 16:55:07 +0100 Organization: Pushface Message-ID: References: <1119966822.201891.303810@g49g2000cwa.googlegroups.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.demon.co.uk 1119974108 6286 62.49.19.209 (28 Jun 2005 15:55:08 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Tue, 28 Jun 2005 15:55:08 +0000 (UTC) Cancel-Lock: sha1:gTYyoRjvQGxgPDi+UGCf4ULar4s= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) Xref: g2news1.google.com comp.lang.ada:11692 Date: 2005-06-28T16:55:07+01:00 List-Id: Marius Amado Alves writes: > On 28 Jun 2005, at 14:53, Bj�rn wrote: > >> I need to read some float values from file that have been written in >> big-endian byte order from a c-program. The simple swapping procedure >> that I have just interchanges the byte order of type IEEE_Float_32 to >> get little-endian. The problem is that for some values (eg. 33.229000) >> it is a "NaN" when doing IEEE_Float_32'Read and I get a constraint >> error (invalid data) from stream_io when the value is read. How do I >> get around this? > > Simple. Setup an array of bytes with the same representation of the > float type (use representation clauses and pragma Pack). Read the > array of bytes. Swap the bytes. Convert to the float type (use > unchecked conversion). Marius, I think you mean 'of the same length as the float type'? OP doesn't say what processor he gets the BE value from, but assuming PowerPC you either get Float (4 bytes) for digits <= 6 or Long_Float (8 bytes) for digits 7 .. 15. On Intel hardware there's an 80-bit Long_Long_Float (digits 18). -S