Because 1
is int
, 32 bits, so (1 << 27)*27
overflowed. Use 1ull
.
As for your comment, if x
is uint64_t
, then 1 << x
is still int
, but for multiplication it will be different to uint64_t
, so there will be no overflow. However, if x >= 31
, 1 << x
will be undefined behavior (since the resulting value cannot be represented as an integer type of 32-bit character).
source share