JDK-7187651 : Integer.parseInt does not support strings of binary literal
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86
  • Submitted: 2012-07-30
  • Updated: 2013-04-10
  • Resolved: 2012-08-01
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
I was try to make algorithm of folded cube adj list (with node that has binary names). I thought I am lucky to use the new feature of Java 7 which support binary literals. My string was like "0b1010". So I tried to save binary values in string and then convert string to int latter by using Integer.parseInt. But it turns out that parseInt does not recognize binary string values and gives an exception.

JUSTIFICATION :
I think java should have support to convert binary strings into integer values otherwise binary literal feature can not be considered as a fully supported feature

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Integer.parseBinaryInt(String str) or Integer.parseBinaryLiteralInt(String str) or
 Integer.parseBinaryLiteral(String str)

---------- BEGIN SOURCE ----------
try{

String _binaryLiteral = "0B1010";
int num;
num = Integer.parseInt(_binaryLiteral);

}catch(NumberFormatException e){

	System.out.println("could not covert binary literal string to integer\n");
	System.out.println(e.toString());
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Add something like following code to parseInt method to make a new parseBinaryInt method
int i = len -1;
while(i >= 0){
	digit = Character.digit(s.charAt(i--),radix);
	if(digit == 1) result += 2^i;
}