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

Discussion in 'Ruby' started by Joachim Just, Jun 22, 2005.

  1. Joachim Just

    Joachim Just Guest

    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
    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
    Joachim Just, Jun 22, 2005
    #1
    1. Advertising

  2. Joachim Just

    Guest

    On Wed, 22 Jun 2005, Joachim Just wrote:

    >
    > 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
    ===============================================================================
    , Jun 22, 2005
    #2
    1. Advertising

  3. Hi,

    "Joachim Just" <> writes:

    > 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

    --
    eban
    WATANABE Hirofumi, Jun 22, 2005
    #3
  4. WATANABE Hirofumi wrote:
    > Hi,
    >
    > "Joachim Just" <> writes:
    >
    >
    >>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
    Daniel Berger, Jun 22, 2005
    #4
  5. Daniel Berger wrote:
    > WATANABE Hirofumi wrote:
    > > Hi,
    > >
    > > "Joachim Just" <> writes:
    > >
    > >
    > >>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
    Charles Mills, Jun 22, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmVyZW15?=

    How can I find out which .net version I'm running?

    =?Utf-8?B?SmVyZW15?=, Apr 9, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,017
    Teemu Keiski
    Apr 10, 2004
  2. Umesh

    Can we replace 8 bits by 2 bits?

    Umesh, Jan 5, 2007, in forum: C Programming
    Replies:
    22
    Views:
    621
    Randy Howard
    Jan 10, 2007
  3. Umesh
    Replies:
    23
    Views:
    679
    Randy Howard
    Jan 10, 2007
  4. Zhi
    Replies:
    2
    Views:
    1,115
    Mike Treseler
    Oct 9, 2007
  5. PerlFAQ Server
    Replies:
    0
    Views:
    103
    PerlFAQ Server
    Mar 7, 2011
Loading...

Share This Page