12,244,103 members (51,722 online)
Rate this:
See more:
Hi All,
I want convert BIG integer value to string
for that i used
_strtoi64
that convert values still 9,223,372,036,854,775,807

but for big value greated than "9,223,372,036,854,775,807" it gives wrong value

have i convert greated than "9,223,372,036,854,775,807" value to string??.
Posted 12-Jan-12 2:16am
Edited 12-Jan-12 2:25am
v2

Rate this:

## Solution 1

What did you expect? A 64 bit integer can handle values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Outside that scope, you'll get an overflow.

If you need bigger numbers than that, you should google for libraries that can handle numbers of unlimited size. That is, if you really need the precision: you could also convert the value to double; in that case you'd still get a meaningful number, but the least significant digits will be cut off. If that is acceptable for your application, use that.
v2
Manfred R. Bihy 12-Jan-12 7:55am

I'd really like to know what kind of application OP is after here. Running into the limits of a 64bit integer seems an indicator of some sort of design flaw, but as long as we don't know what OP is trying to achieve there is no point in reasoning about it.

Cheers!
Stefan_Lang 12-Jan-12 8:01am

Thanks.

There's one application that I know of that requires very big numbers, and that is finding big primes, e.g. for RSA encoding. There's also quite a lot of theoretical work that math people may be involved in, which deals with big primes or 'pseudo primes'.

Other than that, there may be applications that use big numbers as identifiers of some sort, but in that case it may be easier to not try convert the numbers and just store them as strings instead, since they're not used to do real math.
Rate this:

## Solution 2

This is not a simple question to answer: a 64 bit integer (as used as output by _strtoi64) can only hold 64 bit values, and is a signed quantity so you lose one bit to the sign. So when you try to convert string values that are bigger than this, they just don't fit, so it gives you the largest value it can hold: 9,223,372,036,854,775,807

The problem is that not knowing anything about your application, I can't suggest an alternative, because in order to use numbers larger than this you have to abandon 64 bit values throughout - or move to floating point representations.
Manfred R. Bihy 12-Jan-12 7:53am

That just about sums it up nicely! 5+
Rate this:

## Solution 4

If you don´t want to use other library but increase your num support you could try:

_strtoui64() which uses unsigned int and gives you more range:

0 to 18,446,744,073,709,551,615 (_UI64_MAX)

Of course, the variable should be unsigned __int64.
Rate this:

## Solution 3

You may use a `Big Integer` library for the purpose. See instance "C++ Big Integer Library"[^]: if you check out the `sample.cc` file, therein you may find an example of such a conversion.

Top Experts
Last 24hrsThis month
 OriginalGriff 540 BillWoodruff 240 Jochen Arndt 150 ppolymorphe 109 Garth J Lancaster 90
 OriginalGriff 500 BillWoodruff 240 Jochen Arndt 150 ppolymorphe 109 Garth J Lancaster 90