# Huge Numbers in C++

• 04-19-2004
jdm
Huge Numbers in C++
Hi guys...
I'm pretty new to C++. I'm working with Visual C++ 6.0 on Windows XP, doing mainly console apps at the moment.

My question deals with how C++ handles large numbers--like > 5,000,000,000. As I understand it, the biggest number that an int variable can handle is 2,147,483,647, and the biggest than an unsigned int can handle is 4,294,967,295. That ok for most programs... but I can't imagine that no C++ application is able to handle bigger numbers!

Any solutions are welcome--either accepted methods or rough hacks. Is there maybe a header file that I can include that will give me additional data types? Like I said I'm pretty new to this (although I'm familiar with many web-based languages, like JavaScript, PHP, and ASP, so I know the principles of OOP programming). Any help you can provide is extremely welcome... but please treat me like the dumbest programmer you've ever met! All the details are important to me. Thanks!
• 04-19-2004
jdm
By the way, here's the program I'm working on. The goal is to figure out the probabity of 2 out of 100 people in a room sharing the same birthday. Right now, I'm trying to find the probability of the two people not sharing the same day, and the program is coded to generate the numerator:

Code:

```#include <iostream> using namespace std; int main(void) {         int numDays = 365;         int numPeople = 100;         unsigned int product = 1;         for (int i = 0; i < numPeople; i++)         {                 product = product * (numDays - i);                 cout << product << "\n";         }         return 0; }```
Thanks again!
• 04-19-2004
Codeplug
http://cboard.cprogramming.com/search.php?searchid=5250
• 04-19-2004
Thantos
Code:

```#include <iostream> int main(void) {   unsigned long long int x= (unsigned long long)-1;   cout<<"Size:  "<< sizeof x<<endl;   cout<<"Value: "<< x <<endl;   return 0; }```
Output:
Quote:

Size: 8
Value: 18446744073709551615
• 04-20-2004
major_small
Quote:

Originally Posted by Codeplug

look around for a program called 'BigInt' or something to that effect... I've seen it around as a case study-type thing for school courses... I'm not sure if it'll do exactly what you want though...
• 04-20-2004
laserlight
There's the GNU MP library
• 04-20-2004
Codeplug
Damn, I just realized my link is no longer valid....

It was a search on "GMP".

gg
• 04-20-2004
Shakti
Thantos your code gave me an error about long followed by long is illegal. I found that this though would give the same ouput:
Code:

```#include <iostream> int main() {         unsigned __int64 x = (unsigned __int64)-1;         std::cout << x << std::endl; }```
• 04-20-2004
Codeplug
__int64 is MSVC specific....

change "unsigned long long int" to "unsigned long long"

gg
• 04-20-2004
Thantos
Try the following:

cout<<sizeof (long);

If it is 8 then use unsigned long instead of long long.
• 04-20-2004
Codeplug
Quote:

Originally Posted by Codeplug
change "unsigned long long int" to "unsigned long long"

"long long int" is C99 and is suppored in C89 mode by GCC as a compiler extension.

Here's the scoop:
http://gcc.gnu.org/onlinedocs/gcc/Long-Long.html

gg
• 04-20-2004
Tronic
Well normally you would use a 'long' variable for these types of things, as those types of variables reserve more memory, they can take a greater value. And then theres math where you can seperate variables and treat them like normal numbers in base 10. For instance if you had a huge number..lets say 500000000000000000..just some huge number. If you seperated that into multiple variables and _dealt_ with them as one in your programs math/calculations, then you have a way of actually accomplishing that feet.
• 04-21-2004
b00l34n
i also need to use big numbers in an encryption program i am working on.
but i need numbers about 1 * 10^1000
how do i get numbers so big?