Re: How to byte swap an IEEE Float?



"Björn" <ssh9614@xxxxxxxxxxx> wrote in message
news:1119991404.697144.17980@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
....
> 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.

I'd suggest using an array of stream elements for that (presuming that
they're the right size, they would be on almost all machines). That's
especially useful if you're reading the type as a stream in the first place,
because it would let you skip a copy.

If you absolutely have to have portability to any possible machine, then
you'd need to use your own type. But such a machine (such as the 36 bit
Unisys U2200) would probably have problems with 32-bit float values anyway.

Randy.



.



Relevant Pages

  • Re: General Protection Exception
    ... It is a bit unusual to use a float to hold the number of elements of ... an array. ... Each of these pointers is initialized to point to "nowhere". ... Each of the %3.3f terms in the format string means there must be a ...
    (comp.lang.c)
  • Re: General Protection Exception
    ... It is a bit unusual to use a float to hold the number of elements of ... an array. ... Each of these pointers is initialized to point to "nowhere". ... Each of the %3.3f terms in the format string means there must be a ...
    (comp.lang.c)
  • Re: Reopening with a bang: cannot assign to self
    ... String and Array all seem to have #replace. ... But Fixnum, Bignum, Float, and File do not. ...
    (comp.lang.ruby)
  • Re: Can we define data types explicitly?
    ... the 'Integer' is the type - you can also have things like Bignum, Fixnum, Numeric, String, Object, Array etc. ... I am working on application that emphasizes on the data types of the ... I need to check whether the type of 5 is integer or not, 8.9 is float, ...
    (comp.lang.ruby)
  • Re: weird problem
    ... I already told you that the comparison between an integer and a float ... to strcmpwhich expects a pointer to a string. ... And now a question about something else: why do you use floating ... int,float, char, etc. ...
    (comp.lang.c)