Question

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

Was it helpful?

Solution

long long, 64 bit integer... here you can find some reference about the data types and ranges...

OTHER TIPS

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).

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)

If you need really long integers (arbitrary precision), you could also try the gmp library, which also provides a C++ class based interface.

unsigned long long - it is at least 64 bits long

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top