0

I try to do:

String x = "He34llo";
int i = Integer.parseInt(x, 16);
String xx = Integer.toBinaryString(i);

But I get an exception in thread "main" java.lang.NumberFormatException: For input string: "He34llo"

1
  • 3
    Do you know what hexadecimal is? (and how is it represented) Commented Feb 15, 2014 at 23:36

5 Answers 5

1

H, l and o are no valid hexadecimal digits.

Sign up to request clarification or add additional context in comments.

Comments

1

Only the numbers from 0 to 9 and A,B,C,D,E,F are valid Hexadecimal Characters.

See Wikipedia: Hexadecimal for more information about Hexadecimal Numbers.

1 Comment

0-9 are hexadecimal digits as well
1

In short: Your request is imposible.

Explanation:

String x = "He34llo";

can't be converted to hexadecimal because it contains invalid digits.

Hexadecimal can have following: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E and F.

In your case invalid letters are H,l and O.

Comments

0

He34llo is not a valid hexadecimal number, therefore you get error when trying to convert it to one.

Comments

0

0 - To covert String ==> Binary try this : (String=> Hexa decimal ==> Decimal ==>Binary number )

1 - Converting String to Hexa decimal in java:

public String toHex(String arg) {
  return String.format("%x", new BigInteger(1, arg.getBytes(/*YOUR_CHARSET?*/)));
}

2 - Converting Hexa decimal number to Decimal in Java

int decimal = Integer.parseInt(hexadecimal, 16);

3 - Converting Decimal number to binary in Java

String binary = Integer.toBinaryString(decimal);

PS : Hexadecimal can have following: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E and F.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.