title: Bitwise Operators and Binary string evaluations
body: <p>I have an assignment where I have to convert a hexadecimal to a 16 bit binary string and then compare two of these using bitwise operators. I have a for loop which executes <code>a.charAt[i]</code> &amp; <code>b.charAt[i]</code> to a string builder string. Now, I expect that to output a binary number but I've gotten to a point where every time that line executes, it gives me numbers that are not 0 or 1. And it gives me 2 numbers (2 and 3). What am I doing wrong?</p>
  
  <p>Some code:</p>
  
  <pre><code>    int bin = 0;
      hex = hex.replaceFirst("0x", "");
      bin = Integer.parseInt(hex, 16);
      hex = String.format("%16s", Integer.toBinaryString(bin));
      return hex;
  </code></pre>
  
  <p>The two hexadecimals I am trying to evaluate are <code>FFF7</code> and <code>0001</code>. I've successfully converted them to binary strings. Also I don't know why but the preceding zeros are not showing up, just the spaces :/</p>
  
  <p>I've looked online extensively for hours and can't seem to find the problem I am having.</p>