# How to check endianess using ruby?

**URL:** <https://www.ruby-forum.com/t/how-to-check-endianess-using-ruby/156004>\
**Category:** Ruby\
**Created:** [December 19, 2008, 5:42am UTC](https://www.ruby-forum.com/t/how-to-check-endianess-using-ruby/156004 "2008-12-19T05:42:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![flowerborn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/d9b06d/32.png) [@flowerborn](https://www.ruby-forum.com/u/flowerborn)\
**Post date:** [December 19, 2008, 5:42am UTC](https://www.ruby-forum.com/t/how-to-check-endianess-using-ruby/156004/1 "2008-12-19T05:42:49Z")

</div>

Hi,

What’s the right way to check the endianess(big/little endian) of the  
machine  
on which the ruby code run?

Thanks  
Jan

---

<div class="post-metadata">

**Author:** ![flowerborn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/d9b06d/32.png) [@flowerborn](https://www.ruby-forum.com/u/flowerborn)\
**Post date:** [December 19, 2008, 6:11am UTC](https://www.ruby-forum.com/t/how-to-check-endianess-using-ruby/156004/2 "2008-12-19T06:11:27Z")

</div>

Hi,

2008/12/19 Xie H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi,
> 
> What’s the right way to check the endianess(big/little endian) of the machine  
> on which the ruby code run?

[1].pack(‘S’)[0]==1 ? ‘little’ : ‘big’

Regards,  
Park H.

---

<div class="post-metadata">

**Author:** ![flowerborn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/d9b06d/32.png) [@flowerborn](https://www.ruby-forum.com/u/flowerborn)\
**Post date:** [December 19, 2008, 6:55am UTC](https://www.ruby-forum.com/t/how-to-check-endianess-using-ruby/156004/3 "2008-12-19T06:55:54Z")

</div>

- Heesob P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) [2008-12-19 14:02:41 +0900]:

> Hi,
> 
> 2008/12/19 Xie H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > Hi,
> > 
> > What’s the right way to check the endianess(big/little endian) of the machine  
> > on which the ruby code run?
> 
> [1].pack(‘S’)[0]==1 ? ‘little’ : ‘big’

cool thanks 🙂
