-2

I am trying to convert string base address into long value, I tried with different options that do not work.

Option 1: Long.valueoflong(String).longValue(); //not working

Option 2: Long.parseLong(String,16); //not working

Option 3: BigInteger // not working

public class Strconv {

    private static String x1= "0x40000000";
    private static long x2;
    public static void main(String[] args) {
        // TODO Auto-generated method stub


        try {
        x2= Long.valueOf(x1).longValue();
             System.out.println("x2"+x2);
        }
        catch (NumberFormatException e) {

           System.out.println("ERRRORRRRRRRRRRRR");
        }

    }

}
seenukarthi
  • 8,241
  • 10
  • 47
  • 68

1 Answers1

1

Long.parseLong(x2, 16) would work if you didn't have the leading 0x in the string.

If you do have the leading 0x, then you need Long.decode.

Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413