Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Large integer datatypes in C++

  1. #1

    Large integer datatypes in C++

    Lately I've started working on programs that would require me to compute quite large values like those in the order of 10**10. I wrote my own exponentiation function after reading up the 'exponentiation by squaring' algorithm as the cmath function, pow() can return upto long double only which is totally unsuitable for my needs. But the problem is even after specifying the return type as long long unsigned, it seems the return value is too large to fit in it and instead I get a return value of 0.

    I have seen some people using uint32_t and uint64_t datatypes, but I'm not sure what exactly they do. Can somebody guide me in this direction?

  2. #2
    Senior Member nihil's Avatar
    Join Date
    Jul 2003
    Location
    United Kingdom: Bridlington
    Posts
    17,188

  3. #3
    thanks a lot, nihil.
    That should work for all my local computation needs. But, that brings me to another question. You must've seen the online coding contests where you submit your code to the online compiler and get results instantly. I can't use any extra libraries in that case and I've always wondered how those working in C++ manage to handle those large numbers with built-in data types.

    PS: I could've worked the problems out on python, but speed is a major factor.

  4. #4
    Senior Member nihil's Avatar
    Join Date
    Jul 2003
    Location
    United Kingdom: Bridlington
    Posts
    17,188
    Well,

    I believe that quite a lot depends on your compiler?

    This guy seems quite knowledgeable:

    http://home.att.net/~jackklein/c/inttypes.html

    And this discussion:

    http://forums.guru3d.com/showthread.php?t=131678

    This site may also be of interest:

    http://www.dreamincode.net/forums/showtopic4384.htm

    Good luck!

  5. #5
    thanks a lot again, nihil...

    the first link was interesting, reminded me to poke around the /usr/include/limits.h file. I found that a constant _WORDSIZE in bits/wordsize.h that would determine the max size of long unsigned. I'm on a 32 bit system, so that makes it 2**32-1. But I don't think that would depend upon the compiler if I'm using the new compilers that conform to the latest C++ standards. Maybe it would have been a different matter if I was using something like Borland Turbo!

    I have previously worked with GMP, but found the documentation quite cumbersome to follow

  6. #6
    Banned
    Join Date
    Jun 2008
    Posts
    10
    How do i store 1024 bits in C++, As you know at least 1024 bits data is a basic requirement in RSA

  7. #7
    Senior Member nihil's Avatar
    Join Date
    Jul 2003
    Location
    United Kingdom: Bridlington
    Posts
    17,188
    Hi Afsheen and welcome to AO.

    If you are doing C++ and RSA might I suggest this resource?

    http://www.example-code.com/vcpp/rsa.asp

  8. #8
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    I'd recommend taking a look at this book - http://www.amazon.com/Mathematics-Ph...2595774&sr=8-1
    "When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
    "There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
    "Mischief my ass, you are an unethical moron." - chsh
    Blog of X

  9. #9
    Banned
    Join Date
    Jun 2008
    Posts
    10
    Thank you very much, could you please send me all those lists of libraries which are used for large number of bits,or used in RSA, Is MPUINT also used for this purpose if yes ?Then could you please tell me about its funtionality?
    Last edited by Afsheen; June 5th, 2008 at 05:22 AM.

  10. #10
    Member n00bius's Avatar
    Join Date
    Mar 2005
    Location
    texas
    Posts
    86
    I don't know much about large integer types in C++, but i did a course in assembly, and for very large numbers we did multiple operations using a couple of 32bit registers, i.e. you had to add a 64 bit number stored in two 32 bit registers, you'd add with carry and display the number by putting the two registers together. So you could use the largest integer type twice, and just carry the number over to the next order integer, so store a very large number in two variables instead of one. If that makes any sense and/or is possibly in C++.
    ...:::Pure Kn0wledge:::...

Similar Threads

  1. The Basics of Visual Basic
    By mjk in forum Other Tutorials Forum
    Replies: 1
    Last Post: June 20th, 2004, 07:44 PM
  2. The history of the Mac line of Operating systems
    By gore in forum Operating Systems
    Replies: 3
    Last Post: March 7th, 2004, 08:02 AM
  3. Tcp/ip
    By gore in forum Newbie Security Questions
    Replies: 11
    Last Post: December 29th, 2003, 08:01 AM
  4. Basic Integer Overflows
    By tampabay420 in forum Programming Security
    Replies: 0
    Last Post: February 20th, 2003, 03:02 PM
  5. Replies: 1
    Last Post: July 15th, 2002, 03:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •