Considering the following String
String hexData = "1E01";
Is there a simple implementation to turn any hexData into a bit-based String array, like
String hexDataBits = "0001111000000001";
?
Considering the following String
String hexData = "1E01";
Is there a simple implementation to turn any hexData into a bit-based String array, like
String hexDataBits = "0001111000000001";
?
Here you go. Convert your hex string to an int value using the built in parseInt function, then turn that into a binary string.
public String hexToBinary(String hexBits) {
int intversion = Integer.parseInt(hexBits, 16);
String binaryVers = Integer.toBinaryString(intversion);
return binaryVers;
}
Note that this is not padded. If you want to pad it, modify binaryVers.
eg:
// if you're dead set on having at least 16 chars, put this before the return statement
int padding = 16 - binaryVers.length();
while (padding > 0) {
binaryVers = "0" + binaryVers;
padding--;
}