title: Convert binary string to byte-Array in Java
body: <p>I have a binary string and I want to split it into chunks of length 8 and then store the corresponding
  bytes in a byte-Array. For example, the string "0000000011111111" should be convertert to {-128, 127}.
  So far, I wrote the following function:</p>
  
  <pre><code>public static byte[] splitBinary(String binaryString) throws ConversionException {
  
      if (binaryString.length()%8 != 0) {
          throw new ConversionException();
      }
  
      byte[] result = new byte[binaryString.length()/8];
  
      while (i &lt; result.length) {
          result[i] = (byte) (Integer.parseInt(binaryString.substring(i, i+8), 2)-128);
          i+=8;
      }
      return result;
  } 
  </code></pre>
  
  <p>But this results in {-128, 0}. How can I achieve the desired functionality?</p>