title: Convert 4 bytes to int
body: <p>I'm reading a binary file like this:</p>
  
  <pre><code>InputStream in = new FileInputStream( file );
  byte[] buffer = new byte[1024];
  while( ( in.read(buffer ) &gt; -1 ) {
  
     int a = // ??? 
  }
  </code></pre>
  
  <p>What I want to do it to read up to 4 bytes and create a int value from those but, I don't know how to do it. </p>
  
  <p>I kind of feel like I have to grab 4 bytes at a time, and perform one "byte" operation ( like >> &lt;&lt; >> &amp; FF and stuff like that ) to create the new int </p>
  
  <p>What's the idiom for this? </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Ooops this turn out to be a bit more complex ( to explain )  </p>
  
  <p>What I'm trying to do is, read a  file ( may be ascii, binary, it doesn't matter )  and extract the integers it may have. </p>
  
  <p>For instance suppose the binary  content ( in base 2 ) :</p>
  
  <pre><code>00000000 00000000 00000000 00000001
  00000000 00000000 00000000 00000010
  </code></pre>
  
  <p>The integer representation should be <code>1</code> , <code>2</code> right? :- /  1 for the first 32 bits, and 2 for the remaining 32 bits. </p>
  
  <pre><code>11111111 11111111 11111111 11111111
  </code></pre>
  
  <p>Would be -1 </p>
  
  <p>and </p>
  
  <pre><code>01111111 11111111 11111111 11111111
  </code></pre>
  
  <p>Would be  <code>Integer.MAX_VALUE ( 2147483647 )</code> </p>