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

This is a discussion on how to implement a big int class in c++? within the C++ Programming forums, part of the General Programming Boards category; I have a code which gives output larger than 32 bits, so I need a big integer class which can ...

  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
    22,303
    You could consider the C++ wrapper for the GNU MP library.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    22,303
    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.)
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    32,848
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02: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, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21