[squeak-dev] Re: 32 bits single precision float number to a byte array

Andreas Raab andreas.raab at gmx.de
Thu Feb 26 08:57:08 UTC 2009


Serge Stinckwich wrote:
> i'm looking for a way to convert a float (seen as a 32 bits single
> precision float number) as a byte array of length 4 ?

Given that there is no builtin 32bit single precision float type in 
Squeak, how is this float stored? If it's in a float array you can just 
get the bits out of it using #basicAt: and store that. E.g.,

   fltArray := FloatArray with: 42.0.
   word := fltArray basicAt: 1.
   bytes := (ByteArray new: 4) unsignedLongAt: 1 put: word; yourself.

Cheers,
   - Andreas



More information about the Squeak-dev mailing list