Re: How to byte swap an IEEE Float?




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.


.



Relevant Pages

  • Re: How to byte swap an IEEE Float?
    ... > convert first to a float type of that length, ... All the data in the file are of 32 bits float so that should be ok. ... fairly common task. ... better idea than handling it as a string. ...
    (comp.lang.ada)
  • How to check a given string is float-point in (c#) ?thanx
    ... The given string maybe the every type of float type, (the msdn given the ... regax is that: ...
    (microsoft.public.dotnet.languages.csharp)
  • Converting Integer / Float to String
    ... is there another way to convert a given String to an Integer or Float type? ... Alexander ...
    (comp.lang.ada)
  • Re: What my life is really like....
    ... > is variable length and a packed array of char really ... IIRC, original Pascal only had string literals, and these could be ... treated as packed array of char. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Working with packed arrays
    ... problem is the data comes in a packed array of char. ... string to that and use other string functions like delete. ...
    (alt.comp.lang.borland-delphi)