From: Marius Amado Alves <amado.alves@netcabo.pt>
To: comp.lang.ada@ada-france.org
Subject: Re: How to byte swap an IEEE Float?
Date: Wed, 29 Jun 2005 01:13:17 +0100
Date: 2005-06-29T01:13:17+01:00 [thread overview]
Message-ID: <mailman.110.1120004035.17633.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <1119991404.697144.17980@g14g2000cwa.googlegroups.com>
On 28 Jun 2005, at 21:43, Björn wrote:
>> Sure. You know, I meant representation = bits and bytes, implying same
>> length. It seems the OP already has the float type (IEEE_Float_32),
>> 32-bit = 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
String because on your system a String happens to be a packed array of
bytes, but this is not guaranteed for all systems by the standard.
next prev parent reply other threads:[~2005-06-29 0:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-28 13:53 How to byte swap an IEEE Float? Björn
2005-06-28 15:06 ` Marius Amado Alves
2005-06-28 15:55 ` Simon Wright
2005-06-28 16:59 ` Marius Amado Alves
2005-06-28 20:43 ` Björn
2005-06-29 0:13 ` Marius Amado Alves [this message]
2005-06-30 19:14 ` Randy Brukardt
2005-06-28 16:05 ` Martin Dowie
2005-06-28 23:35 ` Stephen Leake
2005-06-29 10:00 ` Björn
2005-06-30 0:52 ` Stephen Leake
2005-07-01 4:51 ` Simon Wright
2005-06-29 20:10 ` Damien
2005-06-30 11:35 ` Peter Hermann
2005-06-30 22:26 ` Damien
2005-07-01 7:37 ` Peter Hermann
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox