If you are on a common computer you can left bitshift 2
by 31
(i.e. 2<<31
) to obtain 2^32.
In standard C:
unsigned long long x = 2ULL << 31;
unsigned long long
is needed since a simple unsigned long
is not guaranteed to be large enough to store the value of 2<<31
.
In section 5.2.4.2.1 paragraph 1 of the C99 standard:
... the
following shall be replaced by expressions that have the same type as would an
expression that is an object of the corresponding type converted according to the integer
promotions. Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign.
— maximum value for an object of type unsigned long int
ULONG_MAX 4294967295 //
2^32 - 1
— maximum value for an object of type unsigned long long int
ULLONG_MAX 18446744073709551615 //
2^64 - 1