[squeak-dev] 32 bit float endian conversion... how?

David T. Lewis lewis at mail.msen.com
Tue Oct 12 12:34:08 UTC 2010


On Tue, Oct 12, 2010 at 05:18:40AM -0700, Lawson English wrote:
>  On 10/12/10 3:29 AM, Nicolas Cellier wrote:
> >I think these two are bigEdian
> >
> >Float pi asIEEE32BitWord.
> >FloatArray with: Float pi.
> >
> Converts it to a 31-bit int, which is not compatible with swapping 
> endianness because you can't index it.
> 
> I'm sure I can eventually analyze what the asIEEE32BitWord is doing and 
> put it into a 4 byte array instead of an int, but I was hoping that 
> someone else had already solved the problem.
> 

(FloatArray with: Float pi) basicAt: 1

This gives you the value as a LargePositiveInteger. If you are running
on a little-endian machine, the value should already be in the byte
order you want. If you need to swap bytes (Smalltalk endianness = #big)
you can use #bitAnd: and shift operators, etc.

Dave




More information about the Squeak-dev mailing list