PROPOSAL: Binary Literals
Mark Thornton
mthornton at optrak.co.uk
Wed Mar 25 15:02:10 PDT 2009
Reinier Zwitserloot wrote:
> To summarize: A bitmask might marginally be more readable in rare
> cases, especially to the casual programmer who doesn't have much
> experience with bit-level trickery, which is small comfort, because
> bitmasking comes up very rarely in java code in the first place. In
> most other situations, binary literals are much worse compared to hex
> literals.
>
>
In many cases bit masks would be more reliably written as expressions.
So if we add methods to Integer (and Byte, Long):
static int bit(int index);
static int bits(int fromIndex, int toIndex);
Then we could write Integer.bits(3, 7). Switch statements require
constant expressions, so for this to be completely convenient it would
be necessary to extend what was allowed in a constant expression to
include the standard bit manipulation methods.
Mark Thornton
More information about the coin-dev
mailing list