# Working with high numbers( 128bit )[C++]

This topic is 4754 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I'm looking for a way to store very big numbers, I think 128 bit would be enough, but it would be nice to be able to work with 256 bit. So how does I do this? Tried something like:
unsigned int Number : 128;


But then it says the bitfield can't be that great for this type. So is there a way to do this? I don't want to depend on compiler-specific implentations like __int64. EDIT: And if there is a way, will it be much slower than standard int(32 bit) calculations?

##### Share on other sites
In the past I have used libgmp which allows for rather arbitrarily sized numbers. It is quite speedy, and for most things, I doubt there will be a noticable difference.

At least when I used it [which was perhaps 3-4 years ago now] the interface was pretty unweildy. It gets the job done though, and a nice C++ wrapper for it might've been completed in the mean time.

##### Share on other sites
What kind of accuracy do you need? You could just use double-precision floating point. It will let you store almost any size number, although if you try adding one to 2.68812*10^35 nothing happens. I have to ask, too -- what are you doing where you need an integer larger than 64 bits? That does go up to about 1*10^19 you know (a couple orders of magnitude more than you need to count the number of seconds since the creation of the universe)...

##### Share on other sites
Thanks that looks just like what I need.

##### Share on other sites
Quote:
 Original post by mumpoWhat kind of accuracy do you need? You could just use double-precision floating point. It will let you store almost any size number, although if you try adding one to 2.68812*10^35 nothing happens. I have to ask, too -- what are you doing where you need an integer larger than 64 bits? That does go up to about 1*10^19 you know (a couple orders of magnitude more than you need to count the number of seconds since the creation of the universe)...

Well, I need pretty much accuracy, the important thing is not to get high numbers, but have a lot of different numbers to chose from, therefore a floating point number wouldn't fit well.

• 36
• 15
• 9
• 23
• 10