title: Need to convert an array of 4 bytes into an int
body: <p>I'm trying to make a reliable UDP system and I need to convert byte[] to int and back (JCreator 5.0 LE)</p>
  
  <p>DatagramPacket requires its data in byte[] form, so I have to convert the int information into byte[] so I can send it:</p>
  
  <pre><code>byte[] data = new byte[48];
  
  System.arraycopy(task.getProtocol().byteValue(), 0, data, 0, task.getProtocol().byteValue().length);
  System.arraycopy(task.getMessage().byteValue(), 0, data, 4, task.getMessage().byteValue().length);
  System.arraycopy(task.getSequence().byteValue(), 0, data, 8, task.getSequence().byteValue().length);
  System.arraycopy(task.getAcknowledge().byteValue(), 0, data, 12, task.getAcknowledge().byteValue().length);
  
  for (int i = task.getAcknowledge(); i &gt;= 0 &amp;&amp; i &gt; task.getAcknowledge() - 33; i--) {
  
      for (Packet j: tasks) {
  
          if (j.getSequence() == i) {
  
              data[i] = 1;
              break;
  
          }
  
      }
  
  }
  
  out = new DatagramPacket(data, data.length, ds.getInetAddress(), portNum);
  ds.send(out);
  </code></pre>
  
  <p>Protocol is the protocolID</p>
  
  <p>Message is the "information" that is being sent</p>
  
  <p>Sequence is the packet's sequence number; the first packet sent has a sequence of 0, the next is 1, and so on</p>
  
  <p>Acknowledge is the acknowledgement of a packet being sent back</p>
  
  <p>The next part is the 32 other acknowledgements.  For the sake of saving memory, they are compressed into 1 byte each instead of 4 bytes (int)</p>
  
  <p>Now, when I receive the packet I need to unpackage it.  First I need to check the first 4 bytes (the protocol) to see if I will ignore the packet or not, but I don't know how to convert the byte array into an int.</p>