making 128 bit integers in C++

Brian23

Banned
Dec 28, 1999
1,655
1
0
I'm writing a program where I need to use REALLY large numbers, so I decided to create a way to use 128 bit integers. I've written a class where I can manipulate the numbers by allocating a block of memory and then treating it as a number, but what I can't do is write code like this:

LargeInteger = LargeInteger + 123789438347598347394839;

I've overloaded the + operator with a 32 bit integer so that it will accept stuff like:

LargeInteger = LargeInteger + 123789;

But I want to be able to type in really large numbers directly into the code and have them added. How would I go about doing this?
 

BFG10K

Lifer
Aug 14, 2000
22,709
3,000
126
Store the numbers as strings and overload your operators to work on them. AFAIK something like this is quite straightforward.
 

singh

Golden Member
Jul 5, 2001
1,449
0
0
The solution will depend upon your requirements - do the operations on big numbers need to be fast? If they do not, just use strings instead of numbers (as per BFG10K's suggestion). If you need them to be fast, look for a commercial library. There should be plenty out there.