[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Endianess of the underlying platform

Tim Pease

10/24/2006 11:40:00 PM

Does ruby provide a global or a method call to determine the endianess
of the underlying platform?

This is what I cooked up, but I'm wondering if there is a ruby way of
doing this.


BIG_ENDIAN = [0xFF00].pack('S') == [0xFF00].pack('n')


Blessings,
TwP

6 Answers

Ara.T.Howard

10/25/2006 12:43:00 AM

0

Tim Pease

10/25/2006 2:56:00 PM

0

On 10/24/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> On Wed, 25 Oct 2006, Tim Pease wrote:
>
> > Does ruby provide a global or a method call to determine the endianess
> > of the underlying platform?
> >
> > This is what I cooked up, but I'm wondering if there is a ruby way of
> > doing this.
> >
> >
> > BIG_ENDIAN = [0xFF00].pack('S') == [0xFF00].pack('n')
> >
> >
> > Blessings,
> > TwP
>
> you could at least have more fun
>
> little_endian = [42].pack('i')[0] == 42
>
> ;-)
>

Very tricksie of you! I'm always amazed at how your mind operates.

TwP

Eric Hodel

11/15/2006 9:19:00 PM

0

On Oct 24, 2006, at 4:40 PM, Tim Pease wrote:

> Does ruby provide a global or a method call to determine the endianess
> of the underlying platform?
>
> This is what I cooked up, but I'm wondering if there is a ruby way of
> doing this.
>
> BIG_ENDIAN = [0xFF00].pack('S') == [0xFF00].pack('n')

Beware, some versions of ruby shipped with OS X have a broken pack
where the endianness is swapped.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...



Austin Ziegler

11/16/2006 1:42:00 PM

0

On 11/16/06, Francis Cianfrocca <garbagecat10@gmail.com> wrote:
> On 11/15/06, Eric Hodel <drbrain@segment7.net> wrote:
> >
> > On Oct 24, 2006, at 4:40 PM, Tim Pease wrote:
> >
> > > Does ruby provide a global or a method call to determine the endianess
> > > of the underlying platform?
> > >
> > > This is what I cooked up, but I'm wondering if there is a ruby way of
> > > doing this.
> > >
> > > BIG_ENDIAN = [0xFF00].pack('S') == [0xFF00].pack('n')
> >
> > Beware, some versions of ruby shipped with OS X have a broken pack
> > where the endianness is swapped.
> Kinky. Is it a bug, or a hack intended to make PowerPCs look like Intel
> chips?

Bug. It was fixed in a later OS update, IIRC.

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca

Eric Hodel

11/16/2006 7:52:00 PM

0

On Nov 16, 2006, at 5:42 AM, Austin Ziegler wrote:
> On 11/16/06, Francis Cianfrocca <garbagecat10@gmail.com> wrote:
>> On 11/15/06, Eric Hodel <drbrain@segment7.net> wrote:
>> > Beware, some versions of ruby shipped with OS X have a broken pack
>> > where the endianness is swapped.
>> Kinky. Is it a bug, or a hack intended to make PowerPCs look like
>> Intel
>> chips?
>
> Bug. It was fixed in a later OS update, IIRC.

Yes. Apple cross-compiled ruby from Intel to PPC and Ruby assumes
the source and target architectures have the same endianness.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...



Charles Oliver Nutter

11/18/2006 4:54:00 PM

0

Eric Hodel wrote:
> On Nov 16, 2006, at 5:42 AM, Austin Ziegler wrote:
>> Bug. It was fixed in a later OS update, IIRC.
>
> Yes. Apple cross-compiled ruby from Intel to PPC and Ruby assumes the
> source and target architectures have the same endianness.

Sounds like a bug in Ruby's build to me...

--
Charles Oliver Nutter, JRuby Core Developer
Blogging on Ruby and Java @ headius.blogspot.com
Help spec out Ruby today! @ www.headius.com/rubyspec
headius@headius.com -- charles.nutter@sun.com