DEV Community

Manav Misra
Manav Misra

Posted on

Answer: How does 1 << 64 - 1 work?

var MaxInt uint64 = 1<<64 - 1

BITSHIFTING In binary, 1, with 64 0s after it (10000...). Same as 2^64.

Handwritten note showing the table of binary numbers and corresponding '2 exponentials'

This maxes out 64-bit unsigned integer (positive numbers only). So, we subtract 1 to prevent the error. Therefore, this is the maximum value unsigned integer we can write.

Top comments (0)