BigInteger in c++

Discussion in 'C++' started by adrin, Jan 5, 2005.

  1. adrin

    adrin Guest

    I have to create a c++ class similar to BigInteger from java...
    but i have no idea, how can i implement big numbers at all(mabye store
    every digit in list element? :))
    how is it properly done?

    thanks for help
     
    adrin, Jan 5, 2005
    #1
    1. Advertising

  2. adrin wrote:

    > I have to create a c++ class similar to BigInteger from java...
    > but i have no idea, how can i implement big numbers at all(mabye store
    > every digit in list element? :))



    Perhaps you could use a vector of ints, longs or even bitsets.


    > how is it properly done?


    Who knows?




    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Jan 5, 2005
    #2
    1. Advertising

  3. adrin wrote:
    > I have to create a c++ class similar to BigInteger from java...
    > but i have no idea, how can i implement big numbers at all(mabye store
    > every digit in list element? :))
    > how is it properly done?


    Google for:

    arbitrary precision c++ library

    I have no first hand experience to talk about, however,

    http://swox.com/gmp/

    seems to be the best I can see.
     
    Gianni Mariani, Jan 5, 2005
    #3
  4. adrin

    gooch Guest

    "I have to create a c++ class similar to BigInteger from java...
    but i have no idea, how can i implement big numbers at all(mabye store
    every digit in list element? :))"

    If by "each digit" you mean each bit representation I think that would
    work. You just need to make sure you
    can access individual bits so that the bit operations like shifting
    etc. can be implemented without too much
    problem. If by digit you mean 13 is represented by two nodes ( 1 and 3)
    depending on how you store them
    the bit manipulations could get confusing. I might create a register
    class that can be
    initialized to hold any arbitrary number of bits required by the user.
    I would include operations such as
    shift left, shift right, circular shift, and , or, etc. You could then
    build your integer class using this register
    class as a base.

    "how is it properly done?"

    I don't think there is a "proper" way. There are many good solutions to
    most problems. Just think first about
    the types of operations you will need to perform on this new type and
    determine what information will
    be needed to complete these operations.
     
    gooch, Jan 5, 2005
    #4
  5. > I have to create a c++ class similar to BigInteger from java...
    > but i have no idea, how can i implement big numbers at all(mabye store
    > every digit in list element? :))
    > how is it properly done?


    Are any informations from the discussion "Proposal: New types in C++0x"
    useful for you?
    http://groups.google.de/groups?threadm=40ed1d8f.0410101304.5ffd7e99@postin
    g.google.com

    Regards,
    Markus
     
    Markus Elfring, Jan 5, 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. pete kirkham
    Replies:
    5
    Views:
    464
    pete kirkham
    Aug 13, 2003
  2. xarax
    Replies:
    6
    Views:
    8,614
    xarax
    Sep 8, 2003
  3. David Goulet

    BigInteger

    David Goulet, Jan 25, 2004, in forum: Java
    Replies:
    1
    Views:
    657
  4. nick
    Replies:
    0
    Views:
    903
  5. nick
    Replies:
    1
    Views:
    31,823
    Eric Sosman
    Oct 26, 2004
Loading...

Share This Page