Java-ASCII Hex to binary conversion

Hi,

I have a 4 bytes string in ASCII Hex, eg) 32:30:30:34, I need to convert into 2 bytes of Hex string to 2004 and further convert it become binary 10000000000100. can anyone show me that how to achieve it ?

I have below code the convert the four bytes of ASCII hex to 2 bytes of Hex.


 public static String convertHexToString(String hex){
		  
		  StringBuilder sb = new StringBuilder();
		  StringBuilder temp = new StringBuilder();
	 
		  for( int i=0; i<hex.length()-1; i+=2 ){
	 
		      String output = hex.substring(i, (i + 2));
	
		      int decimal = Integer.parseInt(output, 16);
		     
		      sb.append((char)decimal);
	 
		      temp.append(decimal);
		  }
		  System.out.println("Decimal : " + temp.toString());
	 
		  return sb.toString();
	  }



However, the binary value is not correct when i convert using method
Integer.toBinaryString(Integer.parseInt(hex))

The binary value given is 11111010100 instead of 10000000000100

problem solved…need to put radix=16