It seems like I should be able to perform bit shift in C/C++ by more than 32 bits provided the left operand of the shift is a long. But this doesn't seem to work, at least with the g++ compiler.
Example:
unsigned long A = (1L << 37)
gives
A = 0
which isn't what I want. Am I missing something or is this just not possible?
-J
A is equal to 0 because A only has 32-bits, so of course you are shifting all the bits off to the left leaving only 0 bits left. You need to make A 64-bit:
unsigned long long A = (1ULL << 37);
Or if you intend to use Visual C++:
unsigned __int64 A = (1ULL << 37);
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