Endianess of the underlying platform

T

Tim Pease

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
 
A

ara.t.howard

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

;-)

-a
 
T

Tim Pease

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
 
E

Eric Hodel

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.
 
A

Austin Ziegler

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
 
E

Eric Hodel

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.
 
C

Charles Oliver Nutter

Eric said:
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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,219
Messages
2,571,117
Members
47,729
Latest member
taulaju99

Latest Threads

Top