Can unsigned long int
hold a ten digits number (1,000,000,000 - 9,999,999,999) on a 32-bit computer?
Additionally, what are the ranges of unsigned long int
, long int
, unsigned int
, short int
, short unsigned int
, and int
?
The INTEGER data type stores whole numbers that range from -2,147,483,647 to 2,147,483,647 for 9 or 10 digits of precision.
What is the range of values that can be stored by int datatype in C? The range of int is from -(2^31) to (2^31) - 1.
The minimum ranges you can rely on are:
short int
and int
: -32,767 to 32,767unsigned short int
and unsigned int
: 0 to 65,535long int
: -2,147,483,647 to 2,147,483,647unsigned long int
: 0 to 4,294,967,295This means that no, long int
cannot be relied upon to store any 10 digit number. However, a larger type long long int
was introduced to C in C99 and C++ in C++11 (this type is also often supported as an extension by compilers built for older standards that did not include it). The minimum range for this type, if your compiler supports it, is:
long long int
: -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807unsigned long long int
: 0 to 18,446,744,073,709,551,615So that type will be big enough (again, if you have it available).
A note for those who believe I've made a mistake with these lower bounds: the C requirements for the ranges are written to allow for ones' complement or sign-magnitude integer representations, where the lowest representable value and the highest representable value differ only in sign. It is also allowed to have a two's complement representation where the value with sign bit 1 and all value bits 0 is a trap representation rather than a legal value. In other words, int
is not required to be able to represent the value -32,768.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With