Andreas Raab a écrit :
> 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.
>
There is a primitive failed in ByteArray>>integerAt:put:size:signed with
your solution ...
Seems to work if i add bigEndian:true :
fltArray := FloatArray with: 42.0.
word := fltArray basicAt: 1.
bytes := (ByteArray new: 4) unsignedLongAt: 1 put: word bigEndian:true;
yourself.
Cheers,
--
Serge Stinckwich
UMI UMMISCO 209 (IRD/UPMC), Hanoi, Vietnam
Smalltalkers do: [:it | All with: Class, (And love: it)]
http://doesnotunderstand.org/