title: Converting big endian to 2-byte number
body: <p>Below are the parameters to send via socket in 5 byte data:</p>
  
  <pre><code>Parameters : methodname(1 byte), payloadlength(2 byte), payload(2 byte)
  
  methodName = 5
  payload = 2151
  </code></pre>
  
  <p>i want to send above three data in only 5 byte.
  The final sending byte are 0500020867. how to get this final bytes ?</p>
  
  <pre><code>  int methodname = 5;
    int payload  = 2151;
  
    ByteBuffer b = ByteBuffer.allocate(4);
          b.putInt(payload);
          byte[] payloadData = b.array();
          int payloadlength = payloadData.length;
  
      byte[] result = new byte[5];
      result[0] = (byte) (methodname);
      result[1] = (byte) (payloadlength &gt;&gt; 8);
      result[2] = (byte) (payloadlength);
      result[3] = (byte) (payload &gt;&gt; 8);
      result[4] = (byte) (payload);
      for (int i = 0; i &lt; 5; i++)
               System.out.printf("%x\n", result[i]);
      result: 5 0 4 8 67 
      //expected result: 05 00 02 08 67
  </code></pre>
  
  <p>Can anybody help me out. Any sort of help would be appreciable.
  Thanks,
  Akash</p>