Return class as Integer

Discussion in 'Ruby' started by Atheeq Pasha, Jan 18, 2010.

  1. Atheeq Pasha

    Atheeq Pasha Guest

    hello,

    Can anyone tell me how to get a return class as Integer in ruby?

    and to use Integer.new method with parameter as a number..
    --
    Posted via http://www.ruby-forum.com/.
    Atheeq Pasha, Jan 18, 2010
    #1
    1. Advertising

  2. Atheeq Pasha

    Gary Wright Guest

    On Jan 18, 2010, at 5:03 PM, Atheeq Pasha wrote:

    > hello,
    >
    > Can anyone tell me how to get a return class as Integer in ruby?
    >
    > and to use Integer.new method with parameter as a number.


    Integer is an abstract class is Ruby. You want a Fixnum
    (32 bit integers) or a Bignum (arbitrarily large integers).

    Fixnum and Bignum are subclasses of Integer. Just use regular
    decimal notation to 'generate' fixnums and bignums instances.

    >> 42.class

    => Fixnum
    >> 4200000000.class

    => Bignum



    Gary Wright
    Gary Wright, Jan 18, 2010
    #2
    1. Advertising

  3. On Jan 18, 2010, at 7:05 PM, lalawawa wrote:

    > Gary Wright wrote:
    >> On Jan 18, 2010, at 5:03 PM, Atheeq Pasha wrote:
    >>> hello,
    >>>
    >>> Can anyone tell me how to get a return class as Integer in ruby?
    >>>
    >>> and to use Integer.new method with parameter as a number.

    >> Integer is an abstract class is Ruby. You want a Fixnum
    >> (32 bit integers) or a Bignum (arbitrarily large integers).
    >> Fixnum and Bignum are subclasses of Integer. Just use regular
    >> decimal notation to 'generate' fixnums and bignums instances.
    >>>> 42.class

    >> => Fixnum
    >>>> 4200000000.class

    >> => Bignum
    >> Gary Wright

    >
    > I don't think Fixnums are 32 bit.
    >
    > irb(main):008:0> (1 << 30).class
    > => Bignum
    > irb(main):009:0> (1 << 29).class
    > => Fixnum
    > irb(main):010:0>
    >
    > This is on Ubuntu Linux.
    >



    No, but they're close enough. There's a few bits used to identify some
    immediate values in the MRI implementation. On a 64-bit platform, a
    Fixnum will be used up to (1 << 62 - 1). The difference tends to
    matter only when you're trying to do true 32-bit (or 64-bit) things
    like cryptographic algorithms where bit shifts or bit rotations are
    defined on an exact word size.

    -Rob

    Rob Biedenharn http://agileconsultingllc.com
    Rob Biedenharn, Jan 19, 2010
    #3
  4. Atheeq Pasha

    Gary Wright Guest

    On Jan 18, 2010, at 7:17 PM, Rob Biedenharn wrote:
    >=20
    >=20
    > No, but they're close enough. There's a few bits used to identify some =

    immediate values in the MRI implementation. On a 64-bit platform, a =
    Fixnum will be used up to (1 << 62 - 1). The difference tends to matter =
    only when you're trying to do true 32-bit (or 64-bit) things like =
    cryptographic algorithms where bit shifts or bit rotations are defined =
    on an exact word size.

    Yep. Thanks for expanding on my post. I just didn't feel like all those =
    details were going to be helpful in the context of the original =
    question.=20

    Gary Wright=
    Gary Wright, Jan 19, 2010
    #4
    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?Sm9l?=

    CType(x,Integer) vs. Integer.Parse(x)

    =?Utf-8?B?Sm9l?=, Feb 6, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    5,930
    =?Utf-8?B?RGF2aWQgQW50b24=?=
    Feb 7, 2006
  2. Purush
    Replies:
    4
    Views:
    1,591
    Purush Rudrakshala
    Apr 13, 2005
  3. E11
    Replies:
    1
    Views:
    4,688
    Thomas Weidenfeller
    Oct 12, 2005
  4. Johannes Zellner
    Replies:
    22
    Views:
    3,543
  5. Greenhorn
    Replies:
    15
    Views:
    786
    Keith Thompson
    Mar 6, 2005
Loading...

Share This Page