title: Convert hexadecimal string (hex) to a binary string
body: <p>I found the following way hex to binary conversion:</p>
  
  <pre><code>String binAddr = Integer.toBinaryString(Integer.parseInt(hexAddr, 16)); 
  </code></pre>
  
  <p>While this approach works for small hex numbers, a hex number such as the following</p>
  
  <pre><code>A14AA1DBDB818F9759
  </code></pre>
  
  <p>Throws a <code>NumberFormatException.</code> </p>
  
  <p>I therefore wrote the following method that seems to work:</p>
  
  <pre><code>private String hexToBin(String hex){
      String bin = "";
      String binFragment = "";
      int iHex;
      hex = hex.trim();
      hex = hex.replaceFirst("0x", "");
  
      for(int i = 0; i &lt; hex.length(); i++){
          iHex = Integer.parseInt(""+hex.charAt(i),16);
          binFragment = Integer.toBinaryString(iHex);
  
          while(binFragment.length() &lt; 4){
              binFragment = "0" + binFragment;
          }
          bin += binFragment;
      }
      return bin;
  }
  </code></pre>
  
  <p>The above method basically takes each character in the Hex string and converts it to its binary equivalent pads it with zeros if necessary then joins it to the return value. 
  Is this a proper way of performing a conversion? Or am I overlooking something that may cause my approach to fail?</p>
  
  <p>Thanks in advance for any assistance.</p>