code: static public int intToBytes(int i, byte[] buffer, int index) {
          int length = buffer.length - index;
          if (length > 4) length = 4;
          for (int j = 0; j < length; j++) {
              buffer[index + length - j - 1] = (byte) (i >> (j * 8));
          }
          return length;
      }
docs: This function converts a integer into its corresponding byte format and inserts
  it into the specified buffer at the specified index.
  
  @param i The integer to be converted.
  @param buffer The byte array.
  @param index The index in the array to begin inserting bytes.
  @return The number of bytes inserted.