How I can find out on which platform I am running (32/64 bits)?

J

Joachim Just

I wonder whether within ruby there is a method to find out on which
platform my application is running.

Unfortunately, the application has to know if it is a 32-bit or 64-bit
system.

Any hints are highly appreciated.

Joachim Just
 
A

Ara.T.Howard

I wonder whether within ruby there is a method to find out on which platform
my application is running.

Unfortunately, the application has to know if it is a 32-bit or 64-bit
system.

Any hints are highly appreciated.

untested, but

[42].pack('L').size * 8 # => 32

this should be the number of bits per long.

you may also be able to get something from Config::CONFIG

hth.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| My religion is very simple. My religion is kindness.
| --Tenzin Gyatso
===============================================================================
 
W

WATANABE Hirofumi

Hi,

Joachim Just said:
I wonder whether within ruby there is a method to find out on which
platform my application is running.

Unfortunately, the application has to know if it is a 32-bit or 64-bit
system.

Any hints are highly appreciated.


64-bit % ruby -ve 'p [0].pack("l!").size'
ruby 1.9.0 (2005-05-31) [x86_64-netbsd]
8

32-bit % ruby -ve 'p [0].pack("l!").size'
ruby 1.9.0 (2005-06-13) [i386-linux]
4
 
D

Daniel Berger

WATANABE said:
Hi,

I wonder whether within ruby there is a method to find out on which
platform my application is running.

Unfortunately, the application has to know if it is a 32-bit or 64-bit
system.

Any hints are highly appreciated.



64-bit % ruby -ve 'p [0].pack("l!").size'
ruby 1.9.0 (2005-05-31) [x86_64-netbsd]
8

32-bit % ruby -ve 'p [0].pack("l!").size'
ruby 1.9.0 (2005-06-13) [i386-linux]
4

That doesn't tell me much on Solaris:
ruby -ve 'p [0].pack("l!").size'
ruby 1.8.2 (2004-12-25) [sparc-solaris2.10]

Ara's approach should work fine, though.

Finding the bitness of Ruby itself is easy. Finding a cross platform
way to find the bitness of the OS itself is another matter. I'm not
sure what the OP is after.

If anyone knows of a good, cross-platform way of finding the bitness of
the OS itself, I'd like to know that myself. :)

Regards,

Dan
 
C

Charles Mills

Daniel said:
WATANABE said:
Hi,

I wonder whether within ruby there is a method to find out on which
platform my application is running.

Unfortunately, the application has to know if it is a 32-bit or 64-bit
system.

Any hints are highly appreciated.



64-bit % ruby -ve 'p [0].pack("l!").size'
ruby 1.9.0 (2005-05-31) [x86_64-netbsd]
8

32-bit % ruby -ve 'p [0].pack("l!").size'
ruby 1.9.0 (2005-06-13) [i386-linux]
4

That doesn't tell me much on Solaris:
ruby -ve 'p [0].pack("l!").size'
ruby 1.8.2 (2004-12-25) [sparc-solaris2.10]

Ara's approach should work fine, though.

Finding the bitness of Ruby itself is easy. Finding a cross platform
way to find the bitness of the OS itself is another matter. I'm not
sure what the OP is after.

If anyone knows of a good, cross-platform way of finding the bitness of
the OS itself, I'd like to know that myself. :)

Regards,

Dan

irb(main):001:0> [1].pack('L')
=> "\001\000\000\000"
irb(main):002:0> [0x01020304].pack('L')
=> "\004\003\002\001"

So I'm on a little endian machine.

-Charlie
 

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

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top