title: Java - Convert byte[] to int[] rgb
body: <p>I have an int array that i obtained by using RobotPeer.getRGBPixels(). I convert it to an byte array to send it over socket by using:</p>
  
  <pre><code> public static byte[] toByteArray(int[] ints){
      byte[] bytes = new byte[ints.length * 4];
              for (int i = 0; i &lt; ints.length; i++) {
          bytes[i * 4] = (byte) (ints[i] &amp; 0xFF);
          bytes[i * 4 + 1] = (byte) ((ints[i] &amp; 0xFF00) &gt;&gt; 8);
          bytes[i * 4 + 2] = (byte) ((ints[i] &amp; 0xFF0000) &gt;&gt; 16);
          bytes[i * 4 + 3] = (byte) ((ints[i] &amp; 0xFF000000) &gt;&gt; 24);
      }
      return bytes;
  }
  </code></pre>
  
  <p><strong>Problem is:</strong>
  I use this method:</p>
  
  <pre><code>public static int[] toIntArray(byte buf[]) {
      int intArr[] = new int[buf.length / 4];
      int offset = 0;
      for (int i = 0; i &lt; intArr.length; i++) {
          intArr[i] = (buf[3 + offset] &amp; 0xFF) | ((buf[2 + offset] &amp; 0xFF) &lt;&lt; 8)
                  | ((buf[1 + offset] &amp; 0xFF) &lt;&lt; 16) | ((buf[0 + offset] &amp; 0xFF) &lt;&lt; 24);
          offset += 4;
      }
      return intArr;
  }
  </code></pre>
  
  <p>to get back int array. Then i create BufferedImage from it and i get:
  <a href="https://www.dropbox.com/s/p754u3tnivigu70/test.jpeg" rel="nofollow">https://www.dropbox.com/s/p754u3tnivigu70/test.jpeg</a></p>
  
  <p>Please help me to solve that problem.</p>