Name: rmT116609 Date: 04/01/2004
A DESCRIPTION OF THE REQUEST :
It's alway struck me as strange that there is no way of writing binary numbers in Java (or C++). Many languages have a syntax for binary literals.
Can I suggest a minor language change allowing for numbers in any base, using a simple syntax such as 2_10111. In practise this would mostly be used for binary, but would be occasionally useful for other bases up to 36.
JUSTIFICATION :
Argument in favour:
It is still a common programming technique to use sets of flags, indeed this is a major use of the forthcoming enum feature.
Flags in hex and decimal are difficult to read, and particularly when a number contains more than one flag. Who could read 0xD9 at a glance? The clearest current representation would be
(1<<7) + (1<<6) + (1<<4) +(1<<3) + (1<<0)
which is clumsy and error-prone, unlike (say) 2_11011001.
Another benefit: writing a set of flags as (say) 2_11011001 clearly expresses that the number is to be interpreted as flags, rather than a true integer.
Another minor benefit: Java's leading-zero octal notation is very unclear and it's easy to switch to octal by accidental as a result of a typo. It could be deprecated (maybe even producing a compiler warning!) in favour of something like 8_...
Argument against: there is resistance to adding to the language in case it increases complexity. Fair enough, but I think this addition actually reduces complexity.
CUSTOMER SUBMITTED WORKAROUND :
Use hex, octal or decimal to express other bases.
(Incident Review ID: 201283)
======================================================================