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!news1.google.com!proxad.net!freenix!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: Wed, 29 Jun 2005 01:13:17 +0100 Organization: Cuivre, Argent, Or Message-ID: References: <1119966822.201891.303810@g49g2000cwa.googlegroups.com> <1119991404.697144.17980@g14g2000cwa.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 1120004036 50196 212.85.156.195 (29 Jun 2005 00:13:56 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Wed, 29 Jun 2005 00:13:56 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: In-Reply-To: <1119991404.697144.17980@g14g2000cwa.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:11715 Date: 2005-06-29T01:13:17+01:00 On 28 Jun 2005, at 21:43, Bj=F6rn wrote: >> Sure. You know, I meant representation =3D bits and bytes, implying = same >> length. It seems the OP already has the float type (IEEE_Float_32), >> 32-bit =3D 4-byte long, and the data are floats of this length, only >> different in byte order. >> >> OP, if the data are of a different length, then you have to unchecked >> convert first to a float type of that length, and then normal convert >> to the final type (risking Constraint_Error). > > All the data in the file are of 32 bits float so that should be ok. > The target for the values is at the moment x86 (although I do expect = it > to work on PowerPC as well so I check System.Default_Bit_Order before > doing any byte swapping). My dirty workaround for the moment was to > read the data as a string. I was merly wondering which is the > normal/"best" way to deal with this, since I expect it to be a > fairly common task. A packed byte array does however seem like a much > better idea than handling it as a string. It is better. Because it's portable. Probably you got away with a=20 String because on your system a String happens to be a packed array of=20= bytes, but this is not guaranteed for all systems by the standard.