Reputation: 2341
I have to use unsigned integers that could span to more than 4 bytes, what type should I use?
PS Sorry for the "noobism" but that's it :D
NB: I need integers because i have to do divisions and care only for the integer parts and this way int are useful
Upvotes: 2
Views: 1847
Reputation: 957
If you need really long integers (arbitrary precision), you could also try the gmp library, which also provides a C++ class based interface.
Upvotes: 2
Reputation: 45535
Simply include <stdint.h> and use int64_t and uint64_t (since you want unsigned, you want uint64_t).
There are several other useful variants on that header, like the least variants (uint_least64_t is a type with at least 64 bits) and the fast variants (uint_fast64_t is the fastest integer type with at least 64 bits). Also very useful are intptr_t/uintptr_t (large enough for a void * pointer) and intmax_t/uintmax_t (largest type).
And if for some reason your compiler doesn't have a <stdint.h> (since IIRC it's a C standard, not a C++ one), you can use Boost's boost/cstdint.hpp (which you can use even if you do have a <stdint.h>, since in that case it should simply forward to the compiler's header).
Upvotes: 12
Reputation: 13872
Take your pick:
long long
(–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
unsigned long long
: (0 to 18,446,744,073,709,551,615)
Upvotes: 5
Reputation: 827198
long long, 64 bit integer... here you can find some reference about the data types and ranges...
Upvotes: 5