class Test{
public static void main(String Args[]){
Integer x;
x = Integer.decode("0b111");
System.out.println(x);
}
}
This doesn’t work with the prefix 0 for binary and for octal with the prefix 0.
What is the correct way to do it?
Looking at the documentation for
Integer.decode, I see no indication that binary should work. Octal should work though, with a prefix of just 0:You could handle a binary indicator of “0b” like this:
Complete sample code showing binary, octal, decimal and hex representations of 15: