Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7187651

Integer.parseInt does not support strings of binary literal

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 7
    • core-libs
    • x86
    • windows_7

      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;
      }

            darcy Joe Darcy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: