Endianess of the underlying platform

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

:wink:

-a

···

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

--
my religion is very simple. my religion is kindness. -- the dalai lama

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

···

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')

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

http://trackmap.robotcoop.com

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

TwP

···

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

:wink:

Kinky. Is it a bug, or a hack intended to make PowerPCs look like Intel
chips?

···

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.

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

-austin

···

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?

--
Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/
               * austin@halostatue.ca * You are in a maze of twisty little passages, all alike. // halo • statue
               * austin@zieglers.ca

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

···

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.

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

http://trackmap.robotcoop.com

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! @ Welcome to headius.com
headius@headius.com -- charles.nutter@sun.com