<?php
 
  function int2bytes($int, $minlen = 4) {
    $tmp = sprintf('%0' . ($minlen * 2) . 'X', $int);
    for ($i = strlen($tmp) - 2; $i > -1; $i -= 2) 
      $ret .= chr(hexdec(substr($tmp, $i, 2)));
    return $ret;
  }

  function bytes2int($str) {
    for ($i = 0; $i < strlen($str); $i++) 
      $ret[] = dechex(ord($str[$i]));
    return hexdec(join('', array_reverse($ret)));
  }

  echo bytes2int(int2bytes(65535));

?>