Convert hex string to binary string
You need to tell Java that the int is in hex, like this:
String hexToBinary(String hex) {
int i = Integer.parseInt(hex, 16);
String bin = Integer.toBinaryString(i);
return bin;
}
the accepted version will only work for 32 bit numbers.
Here's a version that works for arbitrarily long hex strings:
public static String hexToBinary(String hex) {
return new BigInteger(hex, 16).toString(2);
}