0L is a
long integer value with all the bits set to zero – that’s generally the definition of
~ means to invert all the bits, which leaves you with a
long integer with all the bits set to one.
In two’s complement arithmetic (which is almost universal) a signed value with all bits set to one is
The reason for using
~0L instead of
-1L is to be clearer about the intent – it’s not meant to be used as a number at all, but rather as a collection of bits.