# Endianess of the underlying platform

**URL:** <https://www.ruby-forum.com/t/endianess-of-the-underlying-platform/73520>\
**Category:** Ruby\
**Created:** [October 25, 2006, 1:43am UTC](https://www.ruby-forum.com/t/endianess-of-the-underlying-platform/73520 "2006-10-25T01:43:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [October 25, 2006, 1:43am UTC](https://www.ruby-forum.com/t/endianess-of-the-underlying-platform/73520/1 "2006-10-25T01:43:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [October 25, 2006, 2:45am UTC](https://www.ruby-forum.com/t/endianess-of-the-underlying-platform/73520/2 "2006-10-25T02:45:35Z")

</div>

On Wed, 25 Oct 2006, Tim P. wrote:

> Blessings,  
> TwP

you could at least have more fun

little\_endian = [42].pack(‘i’)[0] == 42

😉

-a

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [October 25, 2006, 4:55pm UTC](https://www.ruby-forum.com/t/endianess-of-the-underlying-platform/73520/3 "2006-10-25T16:55:47Z")

</div>

On 10/24/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [November 15, 2006, 10:19pm UTC](https://www.ruby-forum.com/t/endianess-of-the-underlying-platform/73520/4 "2006-11-15T22:19:50Z")

</div>

On Oct 24, 2006, at 4:40 PM, Tim P. 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 H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [November 16, 2006, 2:43pm UTC](https://www.ruby-forum.com/t/endianess-of-the-underlying-platform/73520/5 "2006-11-16T14:43:50Z")

</div>

On 11/16/06, Francis C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [November 16, 2006, 8:53pm UTC](https://www.ruby-forum.com/t/endianess-of-the-underlying-platform/73520/6 "2006-11-16T20:53:24Z")

</div>

On Nov 16, 2006, at 5:42 AM, Austin Z. wrote:

> On 11/16/06, Francis C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > On 11/15/06, Eric H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [November 18, 2006, 5:54pm UTC](https://www.ruby-forum.com/t/endianess-of-the-underlying-platform/73520/7 "2006-11-18T17:54:56Z")

</div>

Eric H. wrote:

> On Nov 16, 2006, at 5:42 AM, Austin Z. 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…

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [November 16, 2006, 1:37pm UTC](https://www.ruby-forum.com/t/endianess-of-the-underlying-platform/73520/8 "2006-11-16T13:37:38Z")

</div>

On 11/15/06, Eric H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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?
