java convert hex to binary method
/**
* Method receives String hexadecimal value (of any range) and returns a String of a binary representation
* hexadecimal string format (ex.:"2FFA")
* Use of if-than-else statement inside for loop
* Use the Integer.toBinaryString(int i) method
*/
private String parseHexBinary(String hex) {
String digits = "0123456789ABCDEF";
hex = hex.toUpperCase();
String binaryString = "";
for(int i = 0; i < hex.length(); i++) {
char c = hex.charAt(i);
int d = digits.indexOf(c);
if(d == 0) binaryString += "0000";
else binaryString += Integer.toBinaryString(d);
}
return binaryString;
}