Transwiki:Create bit mask algorithm

Looks like this when implemented in C:

Note that the equivalent of the above algorithm won't always work properly in Java. Specifically, it fails in the case where (end-start+1 == number of bits in an int), since Java's shift-left operator is cyclic:. Thus, 1<<32 == 1, and the routine will return a bit mask of 0 when it should return a bit mask of 0xFFFFFFFF.

Something like this is needed instead:

The equivalent program in C might be slightly faster than the example given at the beginning of this article.