Numbers beginning with 0
are considered octal – and 9 is not an octal digit (but (conventionally) 0-7 are).
Hexadecimal literals begin with 0x
, e.g. 0xA
.
Up until Java 6, there was no literal notation for binary and
you’ll had to use something like
int a = Integer.parseInt("1011011", 2);
where the second argument specifies the desired base.
Java 7 now has binary literals.
In Java SE 7, the integral types (byte, short, int, and long) can also be expressed using the binary number system. To specify a binary literal, add the prefix
0b
or0B
to the number.