title: How to convert a binary representation of a string into byte in Java?
body: <p>as the title says, how do I do it? Its easy to convert from string -> byte -> string binary, But how do I convert back? Below is a example.
  The output is :
  'f' to binary: 01100110 
  294984</p>
  
  <p>I read somewhere that I could use the Integer.parseInt but clearly that is not the case :( Or am I doing something wrong?</p>
  
  <p>Thanks,
   :)</p>
  
  <pre><code>public class main{
      public static void main(String[] args) {
  
           String s = "f";
            byte[] bytes = s.getBytes();
            StringBuilder binary = new StringBuilder();
            for (byte b : bytes)
            {
               int val = b;
               for (int i = 0; i &lt; 8; i++)
               {
                  binary.append((val &amp; 128) == 0 ? 0 : 1);
                  val &lt;&lt;= 1;
               }
               binary.append(' ');
            }
            System.out.println("'" + s + "' to binary: " + binary);
  
          System.out.println(Integer.parseInt("01100110", 2));
      }
  }
  </code></pre>