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,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable 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!news3.google.com!news2.google.com!proxad.net!usenet-fr.net!news.enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Marius Amado Alves Newsgroups: comp.lang.ada Subject: Re: How to byte swap an IEEE Float? Date: Tue, 28 Jun 2005 16:06:46 +0100 Organization: Cuivre, Argent, Or Message-ID: References: <1119966822.201891.303810@g49g2000cwa.googlegroups.com> NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 (Apple Message framework v622) Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: melchior.cuivre.fr.eu.org 1119971405 62194 212.85.156.195 (28 Jun 2005 15:10:05 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Tue, 28 Jun 2005 15:10:05 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: In-Reply-To: <1119966822.201891.303810@g49g2000cwa.googlegroups.com> X-Mailer: Apple Mail (2.622) X-Virus-Scanned: by amavisd-new at dcc.fc.up.pt X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:11691 Date: 2005-06-28T16:06:46+01:00 On 28 Jun 2005, at 14:53, Bj=F6rn 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=20 float type (use representation clauses and pragma Pack). Read the array=20= of bytes. Swap the bytes. Convert to the float type (use unchecked=20 conversion).=