[Q] Reading little endian DOUBLES on big endian platforms

Andreas Raab andreas.raab at gmx.de
Fri Dec 3 11:09:59 UTC 2004


doubleAt: index bigEndian: bool
    | w1 w2 dbl |
    w1 := self unsignedLongAt: index bigEndian: bool.
    w2 := self unsignedLongAt: index+4 bigEndian: bool
    dbl := Float new: 2.
    bool ifTrue:[
        dbl basicAt: 1 put: w1.
        dbl basicAt: 2 put: w2.
    ] ifFalse:[
        dbl basicAt: 1 put: w2.
        dbl basicAt: 2 put: w1.
    ].
    ^dbl


----- Original Message ----- 
From: "Baveco, Hans" <Hans.Baveco at wur.nl>
To: "The general-purpose Squeak developers list" 
<squeak-dev at lists.squeakfoundation.org>
Sent: Friday, December 03, 2004 11:18 AM
Subject: RE: [Q] Reading little endian DOUBLES on big endian platforms


I am too stupid to be able to write this method.
Until a #doubleAt:bigEndian: methods pops up I will use the workaround of 
swapping the bytes on big endian platforms and using #doubleAt: on the 
swapped bytes. It's not elegant and it may slow down the reading for Mac 
users, but it should work...

Hans



No trick. The method doesn't exist. If you need it you'll have to write your
own.

Cheers,
- Andreas

----- Original Message -----
From: "Baveco, Hans" <Hans.Baveco at w...>
To: "The general-purpose Squeak developers list"
<squeak-dev at l...>
Sent: Friday, December 03, 2004 9:39 AM
Subject: [Q] Reading little endian DOUBLES on big endian platforms


In my Shapes package I make extensive use of the ByteArray>>doubleAt: method
(in the *FFI category), to read little-endian DOUBLES from the contents of a
binary file stream. This #doubleAt: is part of the FFIPlugin, and maybe not
a good general thing to rely on (can it be absent in some Squeak
distributions)? On windows it works fine, but on Mac not (of course). There
doesn't seem to be a doubleAt:bigEndian: method available that allows me to
define the endianness, like there is for integers (longAt:bigEndian: &
shortAt:bigEndian:).

What is the trick here?

Hans





More information about the Squeak-dev mailing list