Thread: how to implement a big int class in c++?

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    7

    how to implement a big int class in c++?

    I have a code which gives output larger than 32 bits, so I need a big integer class which can do addition and multiplication with bi integers. Anybody knows how to write BigInteger class to implement my code? So I can see the bigger integer outputs.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You could consider the C++ wrapper for the GNU MP library.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    7
    I do not want to include a library, I want to implement the big integer class to my code

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by makonikor
    I want to implement the big integer class to my code
    Ah. What ideas do you have in mind right now?

    (You could "cheat" by taking at look at how GMP does it, of course. iMalc also has a bignum library implementation among his useful classes that might (or might not) be easier to understand than GMP's implementation.)
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I want to implement the big integer class to my code
    So do you actually know how to do addition, subtraction, multiplication and division on paper?

    I mean, given
    Code:
    12345678901234567890 +
      987654321987654321
    do you know what to do without pressing buttons on a calculator?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to implement in C++
    By nageshrk1 in forum C++ Programming
    Replies: 7
    Last Post: 02-20-2010, 01:16 PM
  2. Migrating from C, want to implement class
    By HagopH in forum C++ Programming
    Replies: 14
    Last Post: 06-12-2008, 01:31 PM
  3. Replies: 9
    Last Post: 11-12-2007, 03:29 PM
  4. Error when trying to implement a hash table class
    By nempo in forum C++ Programming
    Replies: 5
    Last Post: 10-06-2007, 09:55 AM
  5. Trying To Implement A 'Player' Class
    By adc85 in forum C++ Programming
    Replies: 2
    Last Post: 04-02-2003, 03:51 PM