bit shifting with unsigned long type produces wrong results
Solution 1:
1 << 63
will be computed in int
arithmetic, and your int
is probably 32 bit.
Remedy this by promoting one of the arguments: 1ULL << 63
will do it.
ULL
means the expression will be at least 64 bits.
Solution 2:
The expression 1 << 63
has type int
. The range of an int
is -231 … 231 - 1 on most systems, 263 is too large for that. Try either (unsigned long)1 << 63
or 1UL << 63
to shift a value of type unsigned long
left by 63 places.