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

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Tue Oct 12 12:42:58 UTC 2010


2010/10/12 Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>:
> 2010/10/12 David T. Lewis <lewis at mail.msen.com>:
>> 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
>>
>>
>
> And to make a ByteArray from an Integer between:0 and: 1<<32-1, you
> have a license to be hackish:
>
> (ByteArray newFrom: (Float pi asIEEE32BitWord + 16r100000000))
>        copyFrom: 2 to: 5
>
> Nicolas
>

Oops no, it's rather
(ByteArray newFrom: (Float pi asIEEE32BitWord + 16r100000000)) first: 4

Nicolas



More information about the Squeak-dev mailing list