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"
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"
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.
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.