title: Convert from 2 or 4 bytes to signed/unsigned short/int
body: <p>I have to convert bytes to signed/unsigned int or short. </p>
  
  <p>The methods below are correct? Which is signed and which unsigned?</p>
  
  <p>Byte order: LITTLE_ENDIAN</p>
  
  <pre><code>public static int convertTwoBytesToInt1(byte b1, byte b2) {
      return (int) ((b2 &lt;&lt; 8) | (b1 &amp; 0xFF));
  }
  </code></pre>
  
  <p>VS.</p>
  
  <pre><code>public static int convertTwoBytesToInt2(byte b1, byte b2) {
      return (int) (( (b2 &amp; 0xFF) &lt;&lt; 8) | (b1 &amp; 0xFF));
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public static int  convertFourBytesToInt1(byte b1, byte b2, byte b3, byte b4){
      return (int) ((b4&lt;&lt;24)+(b3&lt;&lt;16)+(b2&lt;&lt;8)+b1);
  }
  </code></pre>
  
  <p>VS.</p>
  
  <pre><code>public static int  convertFourBytesToInt2(byte b1, byte b2, byte b3, byte b4){
      return (int) (( (b4 &amp; 0xFF) &lt;&lt; 24) | ((b3 &amp; 0xFF) &lt;&lt; 16) | ((b2 &amp; 0xFF) &lt;&lt; 8) | (b1 &amp; 0xFF));
  }
  </code></pre>
  
  <p>I'm interested <strong>only</strong> in this conversion forms. Thanks!</p>